List of usage examples for java.io ByteArrayOutputStream flush
public void flush() throws IOException
From source file:com.aqnote.shared.cryptology.cert.io.PKCSTransformer.java
public static String getP12FileString2(KeyStore keyStore, char[] passwd) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); keyStore.store(out, passwd);/* ww w . j a v a 2s . c om*/ out.flush(); String p12File = Base64.encodeBase64String(out.toByteArray()); out.close(); return p12File; }
From source file:com.buddycloud.mediaserver.business.util.ImageUtils.java
public static byte[] imageToBytes(BufferedImage image, String imageFormat) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, imageFormat, baos); baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close();/* w ww. j a va 2s. c o m*/ return imageInByte; }
From source file:Main.java
public static String getStringFromInput(InputStream is) throws IOException { ByteArrayOutputStream byteOus = new ByteArrayOutputStream(); byte[] tmp = new byte[1024]; int size = 0; while ((size = is.read(tmp)) != -1) { byteOus.write(tmp, 0, size);// ww w . java 2 s .c om } byteOus.flush(); is.close(); return byteOus.toString(); }
From source file:Main.java
public static byte[] inputStreamToBytes(InputStream inputStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[2048]; int read = 0; while ((read = inputStream.read(buffer, 0, buffer.length)) != -1) baos.write(buffer, 0, read);/* w w w. j av a 2 s. c o m*/ baos.flush(); return baos.toByteArray(); }
From source file:Main.java
public static byte[] readAll(InputStream is) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); byte[] buf = new byte[1024]; int c = is.read(buf); while (-1 != c) { baos.write(buf, 0, c);/*from ww w. j a v a 2 s. co m*/ c = is.read(buf); } baos.flush(); baos.close(); return baos.toByteArray(); }
From source file:Main.java
public static byte[] getByteArray(InputStream is) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead;//w ww .j a va 2 s .co m byte[] data = new byte[16384]; while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); return buffer.toByteArray(); }
From source file:net.ripe.rpki.commons.crypto.util.KeyPairUtil.java
static String hexEncodeHashData(byte[] keyHashData) { HexEncoder hexEncoder = new HexEncoder(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try {/*from w w w . j a va 2 s . c o m*/ hexEncoder.encode(keyHashData, 0, keyHashData.length, out); out.flush(); return out.toString(); } catch (IOException e) { throw new IllegalArgumentException("Exception hex encoding data", e); } }
From source file:Main.java
public static byte[] unGzip(byte[] data) { byte[] b = null; try {// w ww .j av a 2s . co m ByteArrayInputStream bis = new ByteArrayInputStream(data); GZIPInputStream gzip = new GZIPInputStream(bis); byte[] buf = new byte[1024]; int num = -1; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((num = gzip.read(buf, 0, buf.length)) != -1) { baos.write(buf, 0, num); } b = baos.toByteArray(); baos.flush(); baos.close(); gzip.close(); bis.close(); } catch (Exception ex) { ex.printStackTrace(); } return b; }
From source file:Main.java
private static byte[] getBytes(InputStream is) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] b = new byte[2048]; int len = 0;// w w w .j av a2 s . com try { while ((len = is.read(b, 0, 2048)) != -1) { baos.write(b, 0, len); baos.flush(); } } catch (IOException e) { e.printStackTrace(); } byte[] bytes = baos.toByteArray(); return bytes; }
From source file:Main.java
public static byte[] extract(InputStream inputStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int read;// www . j a va 2 s . com while ((read = inputStream.read(buffer, 0, buffer.length)) != -1) { baos.write(buffer, 0, read); } baos.flush(); return baos.toByteArray(); }