List of usage examples for org.apache.commons.io.output ByteArrayOutputStream close
public void close() throws IOException
From source file:fr.dutra.confluence2wordpress.util.CodecUtils.java
public static String compressAndEncode(String text) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(new Base64OutputStream(baos)); try {// w ww.ja v a 2 s . c om gzos.write(text.getBytes(UTF_8)); } finally { baos.close(); gzos.close(); } return new String(baos.toByteArray(), UTF_8); }
From source file:com.eucalyptus.auth.policy.PolicyParserTest.java
private static String readInputAsString(InputStream in) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[512]; int nRead = 0; while ((nRead = in.read(buf)) >= 0) { baos.write(buf, 0, nRead);/*from ww w. j a va 2 s . c o m*/ } String string = new String(baos.toByteArray(), "UTF-8"); baos.close(); return string; }
From source file:io.digibyte.tools.util.BRCompressor.java
public static byte[] gZipCompress(byte[] data) { if (data == null) return null; byte[] compressedData = null; try {//w w w. j av a 2 s . c om ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length); try { GZIPOutputStream zipStream = new GZIPOutputStream(byteStream); try { zipStream.write(data); } finally { try { zipStream.close(); } catch (IOException e) { e.printStackTrace(); } } } finally { try { byteStream.close(); } catch (IOException e) { e.printStackTrace(); } } compressedData = byteStream.toByteArray(); } catch (Exception e) { BRReportsManager.reportBug(e); e.printStackTrace(); } return compressedData; }
From source file:com.breadwallet.tools.util.BRCompressor.java
public static byte[] gZipCompress(byte[] data) { if (data == null) return null; byte[] compressedData = null; try {//from ww w . j a v a2s . c om ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length); try { GZIPOutputStream zipStream = new GZIPOutputStream(byteStream); try { zipStream.write(data); } finally { try { zipStream.close(); } catch (IOException e) { e.printStackTrace(); } } } finally { try { byteStream.close(); } catch (IOException e) { e.printStackTrace(); } } compressedData = byteStream.toByteArray(); } catch (Exception e) { FirebaseCrash.report(e); e.printStackTrace(); } return compressedData; }
From source file:com.breadwallet.tools.util.BRCompressor.java
public static byte[] bz2Compress(byte[] data) { if (data == null) return null; byte[] compressedData = null; try {/*from w w w . j a v a 2 s. c om*/ ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length); try { BZip2CompressorOutputStream bout = new BZip2CompressorOutputStream(byteStream); try { bout.write(data); } finally { try { bout.close(); } catch (IOException e) { e.printStackTrace(); } } } finally { try { byteStream.close(); } catch (IOException e) { e.printStackTrace(); } } compressedData = byteStream.toByteArray(); } catch (Exception e) { e.printStackTrace(); FirebaseCrash.report(e); } return compressedData; }
From source file:io.digibyte.tools.util.BRCompressor.java
public static byte[] bz2Compress(byte[] data) throws IOException { if (data == null) return null; byte[] compressedData = null; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length); try {/*w w w . ja va 2 s. c o m*/ BZip2CompressorOutputStream bout = new BZip2CompressorOutputStream(byteStream); try { bout.write(data); } catch (Exception e) { throw e; } finally { try { bout.close(); } catch (IOException e) { e.printStackTrace(); } } compressedData = byteStream.toByteArray(); } finally { try { byteStream.close(); } catch (IOException e) { e.printStackTrace(); } } return compressedData; }
From source file:model.PayloadSegment.java
/** * Copy the encapsulation file to the restoration directory first, to be * sure that you won't touch the file in the encapsulation output directory. * //from w w w. ja v a2 s .c o m * @param encapsulatedData * @return altered carrier file... */ public static byte[] removeLeastPayloadSegment(byte[] encapsulatedData) { try { int endIndex = -1; for (int index = encapsulatedData.length - 1; index >= 0; index--) { if (PayloadSequences.isEndSequence(encapsulatedData, index)) { endIndex = index; } else if (PayloadSequences.isStartSequence(encapsulatedData, index)) { if (endIndex == -1) { return null; } ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); byteOut.write(Arrays.copyOfRange(encapsulatedData, 0, index)); if (endIndex + END_SEQ.length > encapsulatedData.length) { byte[] afterPayload = Arrays.copyOfRange(encapsulatedData, endIndex + END_SEQ.length, encapsulatedData.length - 1); byteOut.write(afterPayload); } byte[] dataWithRemovedPayload = byteOut.toByteArray(); byteOut.close(); return dataWithRemovedPayload; } } } catch (IOException e) { } return null; }
From source file:com.vmware.admiral.closures.util.ClosureUtils.java
public static byte[] loadDockerImageData(String dockerImageName, String folderFilter, Class<?> resourceClass) { ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); try {//ww w . j a va2s. c o m URL dirURL = resourceClass.getResource("/" + folderFilter); logInfo("Reading image data %s from: %s ", dockerImageName, dirURL); String extractImageName = extractImageName(dockerImageName); String folderNameFilter = folderFilter + extractImageName; buildTarData(dirURL, folderNameFilter, byteOutputStream); return byteOutputStream.toByteArray(); } catch (Exception ex) { Utils.logWarning("Unable to load docker image data! Reason: ", ex); } finally { try { byteOutputStream.close(); } catch (IOException e) { // not interested } } return new byte[] {}; }
From source file:com.cisco.dbds.utils.selenium.SeleniumUtilities.java
/** * This function captures the Screenshot of the screen and converts it into * a byte array to embed in cucumber reports. * // w ww.ja va 2 s .c o m * @return the byte[] * @throws Exception * the exception */ public static byte[] captureScreen() throws Exception { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle screenRectangle = new Rectangle(screenSize); Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); baos.flush(); byte[] bytes = baos.toByteArray(); baos.close(); return bytes; }
From source file:com.zotoh.core.io.StreamUte.java
private static OutputStream swap(ByteArrayOutputStream baos, StreamData data) throws IOException { Tuple t = createTempFile(true);// w ww . ja v a2 s .co m OutputStream os = (OutputStream) t.get(1); byte[] bits = baos.toByteArray(); if (bits != null && bits.length > 0) { os.write(bits); safeFlush(os); } baos.close(); data.resetMsgContent(t.get(0)); return os; }