Package java.io

Examples of java.io.ByteArrayOutputStream.toByteArray()


      CacheMarshaller200 cm200 = new CacheMarshaller200();
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(bout);
      cm200.objectToObjectStream(l, out);
      out.close();
      ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
      List<Broken> l2 = (List<Broken>) cm200.objectFromObjectStream(in);

      assert l2.size() == 2;
      assert l2.get(0).name.equals("o1");
      assert l2.get(1).name.equals("o2");
View Full Code Here


      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      cm200.objectToObjectStream("Hello World", oos, Fqn.fromString("/hello"));
      oos.close();

      ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));

      // test that the first thing on the stream is the fqn!
      byte magic = ois.readByte();
      short ref = ois.readShort();
      assert magic == CacheMarshaller200.MAGICNUMBER_FQN;
View Full Code Here

      Region r = rm.getRegion(region, true);
      r.registerContextClassLoader(this.getClass().getClassLoader());
      cm200.objectToObjectStream(new ClusteredGetCommand(false, null), oos, region);
      oos.close();

      final byte[] stream = baos.toByteArray();
      // so now the stream starts with the Fqn "/hello".

      // repeat 100 times
      for (int i = 0; i < 100; i++)
      {
View Full Code Here

                     RegionalizedReturnValue rrv = new RegionalizedReturnValue("A result", rmc);
                     cm200.objectToObjectStream(rrv, outStream);
                     outStream.close();
                     out.close();
                     // test that the output stream has got "/hello" as it's region Fqn.
                     ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
                     assert in.readByte() == CacheMarshaller200.MAGICNUMBER_FQN : "The stream should start with an Fqn";
                     // discard the nest refId short
                     in.readShort();
                     Fqn f = cm200.unmarshallFqn(in, new UnmarshalledReferences());
                     assert region.equals(f) : "Should use the same region for the response as was used for the request!";
View Full Code Here

                     ObjectOutputStream outStream = new ObjectOutputStream(out);
                     cm200.objectToObjectStream(true, outStream);
                     outStream.close();
                     out.close();
                     // test that the output stream has got "/hello" as it's region Fqn.
                     ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
                     byte magic = in.readByte();

                     assert magic != CacheMarshaller200.MAGICNUMBER_FQN : "The stream should NOT start with an Fqn!";
                     assert magic == CacheMarshaller200.MAGICNUMBER_NULL : "Should start with a NULL.  Instead, was " + magic;
                     assert in.readByte() == CacheMarshaller200.MAGICNUMBER_BOOLEAN : "Should have a boolean magic number before the boolean value";
View Full Code Here

            }
            if (x == '\r' || x == '\n') {
                if (!lastNewline) {
                    maxLines--;
                    lastNewline = true;
                    byte[] data = buff.toByteArray();
                    String s = new String(data);
                    lines.add(s);
                    buff.reset();
                }
                continue;
View Full Code Here

            if (lastNewline) {
                lastNewline = false;
            }
            buff.write(x);
        }
        byte[] data = buff.toByteArray();
        if (data.length > 0) {
            String s = new String(data);
            lines.add(s);
        }
        return lines;
View Full Code Here

                buff.write(x);
            }
        } catch (IOException e) {
            throw new RuntimeException("Could not read class bytecode", e);
        }
        data = buff.toByteArray();
        int header = readInt();
        debug("header: " + Integer.toHexString(header));
        int minorVersion = readShort();
        int majorVersion = readShort();
        debug("version: " + majorVersion + "." + minorVersion);
View Full Code Here

            }
            in.close();
        } catch (IOException e) {
            throw new RuntimeException("Error downloading", 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

    } else {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(object);
      oos.flush();
      body = baos.toByteArray();
      oos.close();
      baos.close();
    }
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.