Package java.io

Examples of java.io.ByteArrayOutputStream


      oldImpl.put(Fqn.fromString("/a/b/d"), "key2", "value2");
      oldImpl.put(Fqn.fromString("/a/b/e"), "key3", "value3");
      oldImpl.put(Fqn.fromString("/a/f/e"), "key4", "value4");
      oldImpl.put(Fqn.ROOT, "root_key", "root_value");

      ByteArrayOutputStream newBaos = new ByteArrayOutputStream(1024);
      MarshalledValueOutputStream newOs = new MarshalledValueOutputStream(newBaos);
      newImpl.start();
      newImpl.loadState(Fqn.fromString("/a/b"), newOs);
      newImpl.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, newOs);
      newOs.close();

      newImpl.remove(Fqn.fromString("/a/b"));
      assertNull(newImpl.get(Fqn.fromString("/a/b/c")));
      assertNull(newImpl.get(Fqn.fromString("/a/b/d")));
      assertNull(newImpl.get(Fqn.fromString("/a/b/e")));
      assertNull(newImpl.get(Fqn.fromString("/a/b")));

      ByteArrayInputStream bais = new ByteArrayInputStream(newBaos.toByteArray());
      MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
      newImpl.storeState(Fqn.fromString("/a/b"), is);

      assertEquals(newImpl.get(Fqn.fromString("/a/b/c")).get("key1"), "value1");
      assertEquals(newImpl.get(Fqn.fromString("/a/b/d")).get("key2"), "value2");
View Full Code Here


   {
      final InvocationContextContainer icc = getInvocationContextContainer();
      final OwnableReentrantLock lock = new OwnableReentrantLock(icc);
      lock.lock();
      assert lock.isLocked();
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(lock);
      oos.close();
      baos.close();
      ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
      OwnableReentrantLock l2 = (OwnableReentrantLock) ois.readObject();

      assert !l2.isLocked();
      assert l2.getOwner() == null;
   }
View Full Code Here

     *
     * @param fileName the file name
     * @return the content, null if the file doesn't exist
     */
    public byte[] retrieve(String fileName) throws IOException {
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        retrieve(fileName, buff, 0);
        return buff.toByteArray();
    }
View Full Code Here

     */
    public String nameList(String dir) throws IOException {
        passive();
        send("NLST " + dir);
        readCode(150);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copyAndClose(inData, out);
        readCode(226);
        byte[] data = out.toByteArray();
        return new String(data);
    }
View Full Code Here

     */
    public String list(String dir) throws IOException {
        passive();
        send("LIST " + dir);
        readCode(150);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copyAndClose(inData, out);
        readCode(226);
        byte[] data = out.toByteArray();
        return new String(data);
    }
View Full Code Here

      configureCache("", false);
      Fqn X = Fqn.fromString("/x");
      CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
      loader.remove(X);
      cache.put(X, "key1", "value1");
      ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
      MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
      loader.loadEntireState(os);
      cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
      //os.close();
      assertTrue(baos.size() > 0);
      loader.remove(X);

      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
      loader.storeEntireState(is);
      //is.close();
      assertEquals("X found", true, loader.exists(X));
      loader.remove(X);
View Full Code Here

            }
        }

        private boolean processClient(InputStream inStream, OutputStream outStream) throws IOException {
            DataInputStream dataIn = new DataInputStream(inStream);
            ByteArrayOutputStream buff = new ByteArrayOutputStream();
            DataOutputStream dataOut = new DataOutputStream(buff);
            if (state == STATE_INIT_CLIENT) {
                state = STATE_REGULAR;
                int len = dataIn.readInt();
                dataOut.writeInt(len);
                len -= 4;
                byte[] data = new byte[len];
                dataIn.readFully(data, 0, len);
                dataOut.write(data);
                dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
                int version = dataIn.readInt();
                if (version == 80877102) {
                    println("CancelRequest");
                    println(" pid: " + dataIn.readInt());
                    println(" key: " + dataIn.readInt());
                } else if (version == 80877103) {
                    println("SSLRequest");
                } else {
                    println("StartupMessage");
                    println(" version " + version + " (" + (version >> 16) + "." + (version & 0xff) + ")");
                    while (true) {
                        String param = readStringNull(dataIn);
                        if (param.length() == 0) {
                            break;
                        }
                        String value = readStringNull(dataIn);
                        println(" param " + param + "=" + value);
                    }
                }
            } else {
                int x = dataIn.read();
                if (x < 0) {
                    println("end");
                    return false;
                }
                // System.out.println(" x=" + (char)x+" " +x);
                dataOut.write(x);
                int len = dataIn.readInt();
                dataOut.writeInt(len);
                len -= 4;
                byte[] data = new byte[len];
                dataIn.readFully(data, 0, len);
                dataOut.write(data);
                dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
                switch (x) {
                case 'B': {
                    println("Bind");
                    println(" destPortal: " + readStringNull(dataIn));
                    println(" prepName: " + readStringNull(dataIn));
                    int formatCodesCount = dataIn.readShort();
                    for (int i = 0; i < formatCodesCount; i++) {
                        println(" formatCode[" + i + "]=" + dataIn.readShort());
                    }
                    int paramCount = dataIn.readShort();
                    for (int i = 0; i < paramCount; i++) {
                        int paramLen = dataIn.readInt();
                        println(" length[" + i + "]=" + paramLen);
                        byte[] d2 = new byte[paramLen];
                        dataIn.readFully(d2);
                    }
                    int resultCodeCount = dataIn.readShort();
                    for (int i = 0; i < resultCodeCount; i++) {
                        println(" resultCodeCount[" + i + "]=" + dataIn.readShort());
                    }
                    break;
                }
                case 'C': {
                    println("Close");
                    println(" type: (S:prepared statement, P:portal): " + dataIn.read());
                    break;
                }
                case 'd': {
                    println("CopyData");
                    break;
                }
                case 'c': {
                    println("CopyDone");
                    break;
                }
                case 'f': {
                    println("CopyFail");
                    println(" message: " + readStringNull(dataIn));
                    break;
                }
                case 'D': {
                    println("Describe");
                    println(" type (S=prepared statement, P=portal): " + (char) dataIn.readByte());
                    println(" name: " + readStringNull(dataIn));
                    break;
                }
                case 'E': {
                    println("Execute");
                    println(" name: " + readStringNull(dataIn));
                    println(" maxRows: " + dataIn.readShort());
                    break;
                }
                case 'H': {
                    println("Flush");
                    break;
                }
                case 'F': {
                    println("FunctionCall");
                    println(" objectId:" + dataIn.readInt());
                    int columns = dataIn.readShort();
                    for (int i = 0; i < columns; i++) {
                        println(" formatCode[" + i + "]: " + dataIn.readShort());
                    }
                    int count = dataIn.readShort();
                    for (int i = 0; i < count; i++) {
                        int l = dataIn.readInt();
                        println(" len[" + i + "]: " + l);
                        if (l >= 0) {
                            for (int j = 0; j < l; j++) {
                                dataIn.readByte();
                            }
                        }
                    }
                    println(" resultFormat: " + dataIn.readShort());
                    break;
                }
                case 'P': {
                    println("Parse");
                    println(" name:" + readStringNull(dataIn));
                    println(" query:" + readStringNull(dataIn));
                    int count = dataIn.readShort();
                    for (int i = 0; i < count; i++) {
                        println(" [" + i + "]: " + dataIn.readInt());
                    }
                    break;
                }
                case 'p': {
                    println("PasswordMessage");
                    println(" password: " + readStringNull(dataIn));
                    break;
                }
                case 'Q': {
                    println("Query");
                    println(" sql : " + readStringNull(dataIn));
                    break;
                }
                case 'S': {
                    println("Sync");
                    break;
                }
                case 'X': {
                    println("Terminate");
                    break;
                }
                default:
                    println("############## UNSUPPORTED: " + (char) x);
                }
            }
            dataOut.flush();
            byte[] buffer = buff.toByteArray();
            printData(buffer, buffer.length);
            try {
                outStream.write(buffer, 0, buffer.length);
                outStream.flush();
            } catch (IOException e) {
View Full Code Here

            return true;
        }

        private boolean processServer(InputStream inStream, OutputStream outStream) throws IOException {
            DataInputStream dataIn = new DataInputStream(inStream);
            ByteArrayOutputStream buff = new ByteArrayOutputStream();
            DataOutputStream dataOut = new DataOutputStream(buff);
            int x = dataIn.read();
            if (x < 0) {
                println("end");
                return false;
            }
            // System.out.println(" x=" + (char)x+" " +x);
            dataOut.write(x);
            int len = dataIn.readInt();
            dataOut.writeInt(len);
            len -= 4;
            byte[] data = new byte[len];
            dataIn.readFully(data, 0, len);
            dataOut.write(data);
            dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
            switch (x) {
            case 'R': {
                println("Authentication");
                int value = dataIn.readInt();
                if (value == 0) {
                    println(" Ok");
                } else if (value == 2) {
                    println(" KerberosV5");
                } else if (value == 3) {
                    println(" CleartextPassword");
                } else if (value == 4) {
                    println(" CryptPassword");
                    byte b1 = dataIn.readByte();
                    byte b2 = dataIn.readByte();
                    println(" salt1=" + b1 + " salt2=" + b2);
                } else if (value == 5) {
                    println(" MD5Password");
                    byte b1 = dataIn.readByte();
                    byte b2 = dataIn.readByte();
                    byte b3 = dataIn.readByte();
                    byte b4 = dataIn.readByte();
                    println(" salt1=" + b1 + " salt2=" + b2 + " 3=" + b3 + " 4=" + b4);
                } else if (value == 6) {
                    println(" SCMCredential");
                }
                break;
            }
            case 'K': {
                println("BackendKeyData");
                println(" process ID " + dataIn.readInt());
                println(" key " + dataIn.readInt());
                break;
            }
            case '2': {
                println("BindComplete");
                break;
            }
            case '3': {
                println("CloseComplete");
                break;
            }
            case 'C': {
                println("CommandComplete");
                println(" command tag: " + readStringNull(dataIn));
                break;
            }
            case 'd': {
                println("CopyData");
                break;
            }
            case 'c': {
                println("CopyDone");
                break;
            }
            case 'G': {
                println("CopyInResponse");
                println(" format: " + dataIn.readByte());
                int columns = dataIn.readShort();
                for (int i = 0; i < columns; i++) {
                    println(" formatCode[" + i + "]: " + dataIn.readShort());
                }
                break;
            }
            case 'H': {
                println("CopyOutResponse");
                println(" format: " + dataIn.readByte());
                int columns = dataIn.readShort();
                for (int i = 0; i < columns; i++) {
                    println(" formatCode[" + i + "]: " + dataIn.readShort());
                }
                break;
            }
            case 'D': {
                println("DataRow");
                int columns = dataIn.readShort();
                println(" columns : " + columns);
                for (int i = 0; i < columns; i++) {
                    int l = dataIn.readInt();
                    if (l > 0) {
                        for (int j = 0; j < l; j++) {
                            dataIn.readByte();
                        }
                    }
                    // println(" ["+i+"] len: " + l);
                }
                break;
            }
            case 'I': {
                println("EmptyQueryResponse");
                break;
            }
            case 'E': {
                println("ErrorResponse");
                while (true) {
                    int fieldType = dataIn.readByte();
                    if (fieldType == 0) {
                        break;
                    }
                    String msg = readStringNull(dataIn);
                    // http://developer.postgresql.org/pgdocs/postgres/protocol-error-fields.html
                    // S Severity
                    // C Code: the SQLSTATE code
                    // M Message
                    // D Detail
                    // H Hint
                    // P Position
                    // p Internal position
                    // q Internal query
                    // W Where
                    // F File
                    // L Line
                    // R Routine
                    println(" fieldType: " + fieldType + " msg: " + msg);
                }
                break;
            }
            case 'V': {
                println("FunctionCallResponse");
                int resultLen = dataIn.readInt();
                println(" len: " + resultLen);
                break;
            }
            case 'n': {
                println("NoData");
                break;
            }
            case 'N': {
                println("NoticeResponse");
                while (true) {
                    int fieldType = dataIn.readByte();
                    if (fieldType == 0) {
                        break;
                    }
                    String msg = readStringNull(dataIn);
                    // http://developer.postgresql.org/pgdocs/postgres/protocol-error-fields.html
                    // S Severity
                    // C Code: the SQLSTATE code
                    // M Message
                    // D Detail
                    // H Hint
                    // P Position
                    // p Internal position
                    // q Internal query
                    // W Where
                    // F File
                    // L Line
                    // R Routine
                    println(" fieldType: " + fieldType + " msg: " + msg);
                }
                break;
            }
            case 'A': {
                println("NotificationResponse");
                println(" processID: " + dataIn.readInt());
                println(" condition: " + readStringNull(dataIn));
                println(" information: " + readStringNull(dataIn));
                break;
            }
            case 't': {
                println("ParameterDescription");
                println(" processID: " + dataIn.readInt());
                int count = dataIn.readShort();
                for (int i = 0; i < count; i++) {
                    println(" [" + i + "] objectId: " + dataIn.readInt());
                }
                break;
            }
            case 'S': {
                println("ParameterStatus");
                println(" parameter " + readStringNull(dataIn) + " = " + readStringNull(dataIn));
                break;
            }
            case '1': {
                println("ParseComplete");
                break;
            }
            case 's': {
                println("ParseComplete");
                break;
            }
            case 'Z': {
                println("ReadyForQuery");
                println(" status (I:idle, T:transaction, E:failed): " + (char) dataIn.readByte());
                break;
            }
            case 'T': {
                println("RowDescription");
                int columns = dataIn.readShort();
                println(" columns : " + columns);
                for (int i = 0; i < columns; i++) {
                    println(" [" + i + "]");
                    println("  name:" + readStringNull(dataIn));
                    println("  tableId:" + dataIn.readInt());
                    println("  columnId:" + dataIn.readShort());
                    println("  dataTypeId:" + dataIn.readInt());
                    println("  dataTypeSize (pg_type.typlen):" + dataIn.readShort());
                    println("  modifier (pg_attribute.atttypmod):" + dataIn.readInt());
                    println("  format code:" + dataIn.readShort());
                }
                break;
            }
            default:
                println("############## UNSUPPORTED: " + (char) x);
            }
            dataOut.flush();
            byte[] buffer = buff.toByteArray();
            printData(buffer, buffer.length);
            try {
                outStream.write(buffer, 0, buffer.length);
                outStream.flush();
            } catch (IOException e) {
View Full Code Here

      assert map2.get("dont exist") == null;
   }

   private <T> T serializeAndDeserialize(T object) throws Exception
   {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(object);
      oos.close();
      baos.close();

      ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
      Object retval = ois.readObject();
      ois.close();
      return (T) retval;
   }
View Full Code Here

      loader.remove(Fqn.fromString("/"));
      int num;
      try
      {
         ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
         MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
         loader.loadEntireState(os);
         num = baos.size();
      }
      catch (UnsupportedOperationException ex)
      {
         log.info("caught unsupported operation exception that's okay: ", ex);
         return;
      }

      Object txnKey = new Object();
      List<Modification> mods = createUpdates();
      loader.prepare(txnKey, mods, false);
      loader.rollback(txnKey);
      ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
      MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
      loader.loadEntireState(os);
      assertEquals(num, baos.size());
   }
View Full Code Here

TOP

Related Classes of java.io.ByteArrayOutputStream

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.