Package java.io

Examples of java.io.ByteArrayOutputStream


        ts.close();
    }

    private void testTraceDebug() {
        TraceSystem ts = new TraceSystem(null);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ts.setSysOut(new PrintStream(out));
        ts.setLevelSystemOut(TraceSystem.DEBUG);
        ts.getTrace("test").debug(new Exception("error"), "test");
        ts.close();
        String outString = new String(out.toByteArray());
        assertContains(outString, "error");
        assertContains(outString, "Exception");
        assertContains(outString, "test");
    }
View Full Code Here


                    if (image.getRawData() != null){
                        bytes = image.getRawData();
                        put(PdfName.LENGTH, new PdfNumber(bytes.length));
                        return;
                    }
                    streamBytes = new ByteArrayOutputStream();
                    transferBytes(is, streamBytes, -1);
                    break;
                case Image.JPEG2000:
                    put(PdfName.FILTER, PdfName.JPXDECODE);
                    if (image.getColorspace() > 0) {
                        switch(image.getColorspace()) {
                            case 1:
                                put(PdfName.COLORSPACE, PdfName.DEVICEGRAY);
                                break;
                            case 3:
                                put(PdfName.COLORSPACE, PdfName.DEVICERGB);
                                break;
                            default:
                                put(PdfName.COLORSPACE, PdfName.DEVICECMYK);
                        }
                        put(PdfName.BITSPERCOMPONENT, new PdfNumber(image.getBpc()));
                    }
                    if (image.getRawData() != null){
                        bytes = image.getRawData();
                        put(PdfName.LENGTH, new PdfNumber(bytes.length));
                        return;
                    }
                    streamBytes = new ByteArrayOutputStream();
                    transferBytes(is, streamBytes, -1);
                    break;
                default:
                    throw new BadPdfFormatException(errorID + " is an unknown Image format.");
            }
View Full Code Here

  /* (non-Javadoc)
   * @see org.objectweb.joram.shared.stream.Streamable#writeTo(java.io.OutputStream)
   */
  public void writeTo(OutputStream os) throws IOException {
    StreamUtil.writeTo(principal, os);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    try {
      oos.writeObject(subject);
      oos.flush();
      StreamUtil.writeTo(baos.toByteArray(), os);
      oos.close();
      baos.close();
    } finally {
      try {
        oos.close();
      } catch (IOException exc) {}
      try {
        baos.close();
      } catch (IOException exc) {}
    }
  }
View Full Code Here

   * @throws IOException
   */
  public String exception(Throwable t) throws IOException{
    if(t == null)
      return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try{
      t.printStackTrace(new PrintStream(baos));
    }finally{
      baos.close();
    }
    return baos.toString();
  }
View Full Code Here

         * Read the input stream and dump it all into a big byte array
         */
        static byte[] slurpInputStream(InputStream stream) throws IOException {
            final int chunkSize=2048;
            byte[] buf=new byte[chunkSize];
            ByteArrayOutputStream byteStream=new ByteArrayOutputStream(chunkSize);
            int count;

            while((count=stream.read(buf)) != -1) byteStream.write(buf, 0, count);

            return byteStream.toByteArray();
        }
View Full Code Here

        }
      return filePath;
  }
 
  public static final <T extends Serializable> T helpSerialize(T object) throws IOException, ClassNotFoundException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(object);
        oos.flush();
       
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
       
        return (T)ois.readObject();
  }
View Full Code Here

    public TestExternalizeUtil(String name) {
        super(name);
    }

    public void setUp() throws Exception {
        bout = new ByteArrayOutputStream(4096);
        oout = new ObjectOutputStream(bout);
    }
View Full Code Here

        ArrayList test = new ArrayList(Arrays.asList(new String[] {ALPHA_L, ALPHA_U, CLEARTEXT, NUMBERS}));
       
        Object result = randomSymCryptor.sealObject(test);

        //ensure that we can serialize
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(result);
       
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bais);
        result = ois.readObject();
       
        ArrayList clearObject = (ArrayList)randomSymCryptor.unsealObject(result);
       
View Full Code Here

 
    /**
   * @return an XmpMetadata byte array
   */
  private byte[] createXmpMetadataBytes() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
      try {
        XmpWriter xmp = new XmpWriter(baos, pdf.getInfo(), pdfxConformance.getPDFXConformance());
          xmp.close();
      }
      catch(IOException ioe) {
          ioe.printStackTrace();
      }
      return baos.toByteArray();
  }
View Full Code Here

    public static byte[] convertToByteArray(final InputStream is, int length) throws IOException {
      return convertToByteArray(is, length, true);
    }
   
    public static byte[] convertToByteArray(final InputStream is, int length, boolean close) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        write(out, is, length, close);
        out.close();
        return out.toByteArray();     
    }
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.