Package org.apache.commons.io.output

Examples of org.apache.commons.io.output.ByteArrayOutputStream.toByteArray()


            // json -> UTF-8 encode -> gzip -> encrypt -> base64 -> string
            OutputStreamWriter w = new OutputStreamWriter(new GZIPOutputStream(new CombinedCipherOutputStream(baos,getKey(),"AES")), "UTF-8");
            o.write(w);
            w.close();

            return new String(Base64.encode(baos.toByteArray()));
        } catch (GeneralSecurityException e) {
            throw new Error(e); // impossible
        }
    }
View Full Code Here


            logger.error("Exception while writing mutipart to output stream", e);
            throw e;
        }

        ChannelBuffer responseContent = ChannelBuffers.dynamicBuffer();
        responseContent.writeBytes(keysOutputStream.toByteArray());

        // Create the Response object
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);

        // Set the right headers
View Full Code Here

            logger.error("Exception while writing multipart to output stream", e);
            outputStream.close();
            throw e;
        }
        ChannelBuffer responseContent = ChannelBuffers.dynamicBuffer();
        responseContent.writeBytes(outputStream.toByteArray());

        // Create the Response object
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);

        // Set the right headers
View Full Code Here

            oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack
            oos.writeObject(caw.getConsoleAnnotator());
            oos.close();
            StaplerResponse rsp = Stapler.getCurrentResponse();
            if (rsp!=null)
                rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
        } catch (GeneralSecurityException e) {
            throw new IOException2(e);
        }
        return r;
    }
View Full Code Here

            destOutputStream = destination.getOutputStream();

            if (useBuffer) {
                final ByteArrayOutputStream sourceBos = new ByteArrayOutputStream();
                IOUtils.copy(sourceInputStream, sourceBos);
                IOUtils.write(sourceBos.toByteArray(), destOutputStream);
            } else {
                IOUtils.copy(sourceInputStream, destOutputStream);
            }
        } finally {
            if (destOutputStream != null) {
View Full Code Here

                destOutputStream = destinationDocument.getOutputStream();

                if (useBuffer) {
                    final ByteArrayOutputStream sourceBos = new ByteArrayOutputStream();
                    IOUtils.copy(sourceInputStream, sourceBos);
                    IOUtils.write(sourceBos.toByteArray(), destOutputStream);
                } else {
                    IOUtils.copy(sourceInputStream, destOutputStream);
                }
            } finally {
                if (destOutputStream != null) {
View Full Code Here

 
  public static byte[] toBytes(AuthenticationToken token) throws AccumuloSecurityException {
    try {
      ByteArrayOutputStream bais = new ByteArrayOutputStream();
      token.write(new DataOutputStream(bais));
      byte[] serializedToken = bais.toByteArray();
      bais.close();
      return serializedToken;
    } catch (IOException e) {
      log.error(e, e);
      throw new AccumuloSecurityException("unknown", SecurityErrorCode.SERIALIZATION_ERROR);
View Full Code Here

        } catch(IOException e) {
            logger.error("IOException while trying to write the outputStream for an admin response", e);
            throw new RuntimeException(e);
        }
        ChannelBuffer responseContent = ChannelBuffers.dynamicBuffer();
        responseContent.writeBytes(outputStream.toByteArray());
        response.setContent(responseContent);
        if (logger.isDebugEnabled()) {
            logger.debug("Sent " + response);
        }
        return response;
View Full Code Here

        try {
            // Serialize image
            //TODO Eventually, this should be changed not to buffer as this increases the
            //memory consumption (see PostScript output)
            writeImage(image, baout);
            byte[] buf = baout.toByteArray();

            // Generate image
            ImageObject io = afpDataStream.getImageObject(afpx, afpy, afpw,
                    afph, afpres, afpres);
            io.setImageParameters(imageResolution, imageResolution,
View Full Code Here

                value = 0;
            }
        }
        baout.write(value);
        try {
            cidSet.setData(baout.toByteArray());
            descriptor.setCIDSet(cidSet);
        } catch (IOException ioe) {
            log.error(
                    "Failed to write CIDSet [" + cidFont + "] "
                    + cidFont.getEmbedFontName(), ioe);
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.