Package org.hsqldb.lib

Examples of org.hsqldb.lib.DataOutputStream


        try {
            socket.setTcpNoDelay(true);

            dataInput = new DataInputStream(
                new BufferedInputStream(socket.getInputStream()));
            dataOutput = new DataOutputStream(socket.getOutputStream());

            int firstInt = handshake();

            switch (streamProtocol) {
View Full Code Here


                    || type == ResultConstants.RESETSESSION) {
                return;
            }

//
            DataOutputStream dataOut =
                new DataOutputStream(socket.getOutputStream());
            String header = getHead(HEADER_OK, false,
                                    "application/octet-stream", rowOut.size());

            dataOut.write(header.getBytes(ENCODING));
            dataOut.flush();
            resultOut.write(dataOut, rowOut);
            dataOut.close();
        } catch (Exception e) {
            server.printStackTrace(e);
        }
    }
View Full Code Here

            socket = HsqlSocketFactory.getInstance(isTLS).createSocket(host,
                                                   port);

            socket.setTcpNoDelay(true);

            dataOutput = new DataOutputStream(socket.getOutputStream());
            dataInput = new DataInputStream(
                new BufferedInputStream(socket.getInputStream()));

            handshake();
        } catch (Exception e) {
View Full Code Here

                       HttpServletResponse response)
                       throws IOException, ServletException {

        synchronized (this) {
            DataInputStream  inStream = null;
            DataOutputStream dataOut  = null;

            try {

                // fredt@users - the servlet container, Resin does not return all
                // the bytes with one call to input.read(b,0,len) when len > 8192
                // bytes, the loop in the Result.read() method handles this
                inStream = new DataInputStream(request.getInputStream());

                int  databaseID = inStream.readInt();
                long sessionID  = inStream.readLong();
                int  mode       = inStream.readByte();
                Session session = DatabaseManager.getSession(databaseID,
                    sessionID);
                Result resultIn = Result.newResult(session, mode, inStream,
                                                   rowIn);

                resultIn.setDatabaseId(databaseID);
                resultIn.setSessionId(sessionID);

                Result resultOut;

                if (resultIn.getType() == ResultConstants.CONNECT) {
                    try {
                        session = DatabaseManager.newSession(
                            dbType, dbPath, resultIn.getMainString(),
                            resultIn.getSubString(), new HsqlProperties(),
                            resultIn.getZoneString(),
                            resultIn.getUpdateCount());

                        resultIn.readAdditionalResults(null, inStream, rowIn);

                        resultOut = Result.newConnectionAcknowledgeResponse(
                            session.getDatabase(), session.getId(),
                            session.getDatabase().getDatabaseID());
                    } catch (HsqlException e) {
                        resultOut = Result.newErrorResult(e);
                    }
                } else {
                    int  dbId      = resultIn.getDatabaseId();
                    long sessionId = resultIn.getSessionId();

                    session = DatabaseManager.getSession(dbId, sessionId);

                    resultIn.readAdditionalResults(session, inStream, rowIn);

                    resultOut = session.execute(resultIn);
                }

                //
                response.setContentType("application/octet-stream");
                response.setContentLength(rowOut.size());

                //
                dataOut = new DataOutputStream(response.getOutputStream());

                resultOut.write(dataOut, rowOut);

                iQueries++;
            } catch (HsqlException e) {}
            finally {
                if (dataOut != null) {
                    dataOut.close();
                }

                if (inStream != null) {
                    inStream.close();
                }
View Full Code Here

            socket = HsqlSocketFactory.getInstance(isTLS).createSocket(socket,
                                                   host, port);

            socket.setTcpNoDelay(true);

            dataOutput = new DataOutputStream(socket.getOutputStream());
            dataInput = new DataInputStream(
                new BufferedInputStream(socket.getInputStream()));

            handshake();
        } catch (Exception e) {
View Full Code Here

    }

    protected void write(Result r) throws IOException, HsqlException {

        HsqlByteArrayOutputStream memStream  = new HsqlByteArrayOutputStream();
        DataOutputStream          tempOutput = new DataOutputStream(memStream);

        r.write(this, tempOutput, rowOut);
        httpConnection.setRequestMethod("POST");
        httpConnection.setDoOutput(true);
        httpConnection.setUseCaches(false);

        //httpConnection.setRequestProperty("Accept-Encoding", "gzip");
        httpConnection.setRequestProperty("Content-Type",
                                          "application/octet-stream");
        httpConnection.setRequestProperty("Content-Length",
                                          String.valueOf(IDLENGTH
                                              + memStream.size()));

        dataOutput = new DataOutputStream(httpConnection.getOutputStream());

        dataOutput.writeInt(r.getDatabaseId());
        dataOutput.writeLong(r.getSessionId());
        memStream.writeTo(dataOutput);
        dataOutput.flush();
View Full Code Here

                       HttpServletResponse response)
                       throws IOException, ServletException {

        synchronized (this) {
            DataInputStream  inStream = null;
            DataOutputStream dataOut  = null;

            try {

                // fredt@users - the servlet container, Resin does not return all
                // the bytes with one call to input.read(b,0,len) when len > 8192
                // bytes, the loop in the Result.read() method handles this
                inStream = new DataInputStream(request.getInputStream());

                int  databaseID = inStream.readInt();
                long sessionID  = inStream.readLong();
                int  mode       = inStream.readByte();
                Session session = DatabaseManager.getSession(databaseID,
                    sessionID);
                Result resultIn = Result.newResult(session, mode, inStream,
                                                   rowIn);

                resultIn.setDatabaseId(databaseID);
                resultIn.setSessionId(sessionID);

                Result resultOut;
                int    type = resultIn.getType();

                if (type == ResultConstants.CONNECT) {
                    try {
                        session = DatabaseManager.newSession(
                            dbType, dbPath, resultIn.getMainString(),
                            resultIn.getSubString(), new HsqlProperties(),
                            resultIn.getZoneString(),
                            resultIn.getUpdateCount());

                        resultIn.readAdditionalResults(null, inStream, rowIn);

                        resultOut = Result.newConnectionAcknowledgeResponse(
                            session.getDatabase(), session.getId(),
                            session.getDatabase().getDatabaseID());
                    } catch (HsqlException e) {
                        resultOut = Result.newErrorResult(e);
                    }
                } else if (type == ResultConstants.DISCONNECT
                           || type == ResultConstants.RESETSESSION) {

                    // Upon DISCONNECT 6 bytes are read by the ClientConnectionHTTP": mode (1 byte), a length (int), and an 'additional results (1 byte)
                    response.setHeader("Cache-Control", "no-cache");    // DB-traffic should not be cached by proxy's
                    response.setContentType("application/octet-stream");
                    response.setContentLength(6);

                    // Only acquire output-stream after headers are set
                    dataOut = new DataOutputStream(response.getOutputStream());

                    dataOut.writeByte(ResultConstants.DISCONNECT);      // Mode
                    dataOut.writeInt(4);                                //Length Int of first result is always read! Minvalue is 4: It is the number of bytes of the current result (it includes the length of this Int itself)
                    dataOut.writeByte(ResultConstants.NONE);            // No Additional results
                    dataOut.close();

                    return;
                } else {
                    int  dbId      = resultIn.getDatabaseId();
                    long sessionId = resultIn.getSessionId();

                    session = DatabaseManager.getSession(dbId, sessionId);

                    resultIn.readLobResults(session, inStream, rowIn);

                    resultOut = session.execute(resultIn);
                }

                HsqlByteArrayOutputStream memStream =
                    new HsqlByteArrayOutputStream();
                DataOutputStream tempOutput = new DataOutputStream(memStream);

                resultOut.write(session, tempOutput, rowOut);
                response.setHeader("Cache-Control", "no-cache");        // DB-traffic should not be cached by proxy's
                response.setContentType("application/octet-stream");
                response.setContentLength(memStream.size());

                // Only acquire output-stream after headers are set
                dataOut = new DataOutputStream(response.getOutputStream());

                memStream.writeTo(dataOut);

                iQueries++;
            } catch (HsqlException e) {}
View Full Code Here

            int type = resultIn.getType();

// patched 2.2.9 by Aart 2012-05-15: Make sure 'Content-length' is correctly set
            if (type == ResultConstants.DISCONNECT
                    || type == ResultConstants.RESETSESSION) {
                DataOutputStream dataOut =
                    new DataOutputStream(socket.getOutputStream());

                // Upon DISCONNECT 6 bytes are read by the ClientConnectionHTTP": mode (1 byte), a length (int), and an 'additional results (1 byte)
                String header = getHead(HEADER_OK, false,
                                        "application/octet-stream", 6);

                dataOut.write(header.getBytes(ENCODING));
                dataOut.writeByte(ResultConstants.DISCONNECT);    // Mode
                dataOut.writeInt(4);                              //Length Int of first result is always read! Minvalue is 4: It is the number of bytes of the current result (it includes the length of this Int itself)
                dataOut.writeByte(ResultConstants.NONE);          // No Additional results
                dataOut.close();

                return;
            }

            // TODO: when doing Keep-Alive connections, try to retain buffer
            HsqlByteArrayOutputStream memStream =
                new HsqlByteArrayOutputStream();
            DataOutputStream tempOutput = new DataOutputStream(memStream);

            resultOut.write(session, tempOutput, rowOut);

            DataOutputStream dataOut =
                new DataOutputStream(socket.getOutputStream());

            // Write HTTP response header
            String header = getHead(HEADER_OK, false,
                                    "application/octet-stream",
                                    memStream.size());

            dataOut.write(header.getBytes(ENCODING));

            // Write actual pay-load to response
            memStream.writeTo(dataOut);
            dataOut.close();

// patch-end 2.2.9 by Aart 2012-05-15
        } catch (Exception e) {
            server.printStackTrace(e);
        }
View Full Code Here

        try {
            socket.setTcpNoDelay(true);

            dataInput = new DataInputStream(
                new BufferedInputStream(socket.getInputStream()));
            dataOutput = new DataOutputStream(socket.getOutputStream());

            int firstInt = handshake();

            switch (streamProtocol) {
View Full Code Here

                       HttpServletResponse response)
                       throws IOException, ServletException {

        synchronized (this) {
            DataInputStream  inStream = null;
            DataOutputStream dataOut  = null;

            try {

                // fredt@users - the servlet container, Resin does not return all
                // the bytes with one call to input.read(b,0,len) when len > 8192
                // bytes, the loop in the Result.read() method handles this
                inStream = new DataInputStream(request.getInputStream());

                int  databaseID = inStream.readInt();
                long sessionID  = inStream.readLong();
                int  mode       = inStream.readByte();
                Session session = DatabaseManager.getSession(databaseID,
                    sessionID);
                Result resultIn = Result.newResult(session, mode, inStream,
                                                   rowIn);

                resultIn.setDatabaseId(databaseID);
                resultIn.setSessionId(sessionID);

                Result resultOut;

                if (resultIn.getType() == ResultConstants.CONNECT) {
                    try {
                        session = DatabaseManager.newSession(
                            dbType, dbPath, resultIn.getMainString(),
                            resultIn.getSubString(), new HsqlProperties(),
                            resultIn.getZoneString(),
                            resultIn.getUpdateCount());

                        resultIn.readAdditionalResults(null, inStream, rowIn);

                        resultOut = Result.newConnectionAcknowledgeResponse(
                            session.getDatabase(), session.getId(),
                            session.getDatabase().getDatabaseID());
                    } catch (HsqlException e) {
                        resultOut = Result.newErrorResult(e);
                    }
                } else {
                    int  dbId      = resultIn.getDatabaseId();
                    long sessionId = resultIn.getSessionId();

                    session = DatabaseManager.getSession(dbId, sessionId);

                    resultIn.readLobResults(session, inStream, rowIn);

                    resultOut = session.execute(resultIn);
                }

                //
                response.setContentType("application/octet-stream");
                response.setContentLength(rowOut.size());

                //
                dataOut = new DataOutputStream(response.getOutputStream());

                resultOut.write(session, dataOut, rowOut);

                iQueries++;
            } catch (HsqlException e) {}
            finally {
                if (dataOut != null) {
                    dataOut.close();
                }

                if (inStream != null) {
                    inStream.close();
                }
View Full Code Here

TOP

Related Classes of org.hsqldb.lib.DataOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.