Package java.io

Examples of java.io.ByteArrayOutputStream


      InputStream     is,
      AsyncController    async )
   
      throws IOException
    {
      ByteArrayOutputStream  os = new ByteArrayOutputStream( 1024 );
     
      InetSocketAddress  local_address = null// TODO
     
      processRequest(input_header, lowercase_input_header, url_path, local_address, remote_address, announce_and_scrape_only, false, is, os, async );
     
View Full Code Here


      /* One FQN only. */
      doPutTests(FQN);
      doRemoveTests(FQN);

      ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
      MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
      loader.loadEntireState(os);
      os.close();

      /* Add three FQNs, middle FQN last. */
      Fqn k1 = Fqn.fromString("/key1");
      Fqn k2 = Fqn.fromString("/key2");
      Fqn k3 = Fqn.fromString("/key3");

      doPutTests(k1);
      doPutTests(k3);
      doPutTests(k2);
      assertEquals(4, loader.get(k1).size());
      assertEquals(4, loader.get(k2).size());
      assertEquals(4, loader.get(k3).size());

      /* Remove middle FQN first, then the others. */
      doRemoveTests(k2);
      doRemoveTests(k3);
      doRemoveTests(k1);
      assertEquals(null, loader.get(k1));
      assertEquals(null, loader.get(k2));
      assertEquals(null, loader.get(k3));

      baos = new ByteArrayOutputStream(1024);
      os = new MarshalledValueOutputStream(baos);
      loader.loadEntireState(os);
      os.close();

      stopLoader();
View Full Code Here

      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);
      os.close();

      stopLoader();
View Full Code Here

      {
      }

      /* Commit and rollback after commit. */

      ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
      MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
      cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
      os.close();

      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
      loader.storeEntireState(is);
      is.close();

      Object txnKey = new Object();
      loader.prepare(txnKey, mods, false);
      loader.commit(txnKey);
      try
      {
         loader.commit(txnKey);
         fail();
      }
      catch (IllegalArgumentException expected)
      {
      }
      try
      {
         loader.rollback(txnKey);
         fail();
      }
      catch (IllegalArgumentException expected)
      {
      }

      /* Commit and rollback after rollback. */
      bais = new ByteArrayInputStream(baos.toByteArray());
      is = new MarshalledValueInputStream(bais);
      loader.storeEntireState(is);
      is.close();
      txnKey = new Object();
      loader.prepare(txnKey, mods, false);
View Full Code Here

   public void testLoadAndStore() throws Exception
   {
      startLoader(false, null);

      /* Empty state. */
      ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
      MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
      loader.loadEntireState(os);
      cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
      os.close();

      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      MarshalledValueInputStream is = new MarshalledValueInputStream(bais);
      loader.storeEntireState(is);
      is.close();

      baos = new ByteArrayOutputStream(1024);
      os = new MarshalledValueOutputStream(baos);
      loader.loadEntireState(os);
      cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
      os.close();

      bais = new ByteArrayInputStream(baos.toByteArray());
      is = new MarshalledValueInputStream(bais);
      loader.storeEntireState(is);
      is.close();

      baos = new ByteArrayOutputStream(1024);
      os = new MarshalledValueOutputStream(baos);
      loader.loadEntireState(os);
      cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
      os.close();

      assertEquals(null, loader.get(FQN));

      /* Use a complex object to ensure that the class catalog is used. */
      Complex c1 = new Complex();
      Complex c2 = new Complex(c1);

      /* Add objects. */
      loader.put(FQN, 1, c1);
      loader.put(FQN, 2, c2);
      assertEquals(c1, loader.get(FQN).get(1));
      assertEquals(c2, loader.get(FQN).get(2));
      assertEquals(2, loader.get(FQN).size());

      /* Save state. */
      baos = new ByteArrayOutputStream(1024);
      os = new MarshalledValueOutputStream(baos);
      loader.loadEntireState(os);
      cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
      assertTrue(baos.size() > STREAM_HEADER_LENGTH);
      os.close();

      byte[] savedState = baos.toByteArray();

      /* Clear state. */
      baos = new ByteArrayOutputStream(1024);
      os = new MarshalledValueOutputStream(baos);
      cache.getMarshaller().objectToObjectStream(DefaultStateTransferManager.STREAMING_DELIMITER_NODE, os);
      os.close();
      bais = new ByteArrayInputStream(baos.toByteArray());
      is = new MarshalledValueInputStream(bais);
      loader.storeEntireState(is);
      is.close();

      assertEquals(null, loader.get(FQN));
View Full Code Here

   @BeforeMethod(alwaysRun = true)
   public void setUp() throws Exception
   {

      byteStream = new ByteArrayOutputStream();
      stream = new ObjectOutputStream(byteStream);
      command1 = new PutDataMapCommand(null, Fqn.ROOT, null);

      list = new ArrayList<WriteCommand>(2);
      list.add(command1);
View Full Code Here

      }
   }

   private int getAndTestSize(CacheMarshaller200 m, int i) throws IOException
   {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      m.writeUnsignedInt(oos, i);
      oos.flush();
      oos.close();
      baos.flush();
      baos.close();
      byte[] bytes = baos.toByteArray();
      int byteL = bytes.length;
      assert i == m.readUnsignedInt(new ObjectInputStream(new ByteArrayInputStream(bytes)));
      return byteL;
   }
View Full Code Here

      return byteL;
   }

   private int getAndTestSize(CacheMarshaller200 m, long i) throws IOException
   {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      m.writeUnsignedLong(oos, i);
      oos.flush();
      oos.close();
      baos.flush();
      baos.close();
      byte[] bytes = baos.toByteArray();
      int byteL = bytes.length;
      assert i == m.readUnsignedLong(new ObjectInputStream(new ByteArrayInputStream(bytes)));
      return byteL;
   }
View Full Code Here

        }
    }

    private PrintStream filter(PrintStream out, final String[] exclude) {
        return new PrintStream(new FilterOutputStream(out) {
            private ByteArrayOutputStream buff = new ByteArrayOutputStream();

            public void write(byte[] b) throws IOException {
                write(b, 0, b.length);
            }

            public void write(byte[] b, int off, int len) throws IOException {
                for (int i = off; i < len; i++) {
                    write(b[i]);
                }
            }

            public void write(byte b) throws IOException {
                buff.write(b);
                if (b == '\n') {
                    byte[] data = buff.toByteArray();
                    String line = new String(data, "UTF-8");
                    boolean print = true;
                    for (String l : exclude) {
                        if (line.startsWith(l)) {
                            print = false;
                            break;
                        }
                    }
                    if (print) {
                        out.write(data);
                    }
                    buff.reset();
                }
            }

            public void close() throws IOException {
                write('\n');
View Full Code Here

        File targetFile = new File(target);
        if (targetFile.exists()) {
            return;
        }
        mkdirs(targetFile.getAbsoluteFile().getParentFile());
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        try {
            println("Downloading " + fileURL);
            URL url = new URL(fileURL);
            InputStream in = new BufferedInputStream(url.openStream());
            long last = System.currentTimeMillis();
            int len = 0;
            while (true) {
                long now = System.currentTimeMillis();
                if (now > last + 1000) {
                    println("Downloaded " + len + " bytes");
                    last = now;
                }
                int x = in.read();
                len++;
                if (x < 0) {
                    break;
                }
                buff.write(x);
            }
            in.close();
        } catch (IOException e) {
            throw new RuntimeException("Error downloading " + fileURL + " to " + target, e);
        }
        byte[] data = buff.toByteArray();
        String got = getSHA1(data);
        if (sha1Checksum == null) {
            println("SHA1 checksum: " + got);
        } else {
            if (!got.equals(sha1Checksum)) {
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.