List of usage examples for java.io ByteArrayOutputStream size
public synchronized int size()
From source file:Main.java
public static String readInputStreamAsString(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] bytes = new byte[4096]; int lenRead;//from w w w . jav a 2s.c om while ((lenRead = is.read(bytes)) != -1) { if (lenRead > 0) baos.write(bytes, 0, lenRead); } if (baos.size() > 0) return baos.toString("utf-8"); return null; }
From source file:org.casbah.provider.SSLeayEncoder.java
private static DESedeKeySpec calculateKeyFromPassKey(byte[] keypass, byte[] salt) throws IOException, GeneralSecurityException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digest = null; while (baos.size() < 24) { md.reset();// w w w.j av a 2 s.c o m if (digest != null) { md.update(digest); } md.update(keypass); digest = md.digest(salt); baos.write(digest); } DESedeKeySpec result = new DESedeKeySpec(baos.toByteArray()); return result; }
From source file:dk.netarkivet.common.utils.InputStreamUtils.java
/** * Reads a raw line from an InputStream, up till \n. Since HTTP allows \r\n and \n as terminators, this gets the * whole line. This code is adapted from org.apache.commons.httpclient.HttpParser * * @param inputStream A stream to read from. * @return Array of bytes read or null if none are available. * @throws IOException if the underlying reads fail *///w ww.ja v a2 s . co m public static byte[] readRawLine(InputStream inputStream) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); int ch; while ((ch = inputStream.read()) >= 0) { buf.write(ch); if (ch == '\n') { break; } } if (buf.size() == 0) { return null; } return buf.toByteArray(); }
From source file:com.discovery.darchrow.io.SerializableUtil.java
/** * Size.//from ww w. ja v a2 s. c o m * * @param serializable * the serializable * @return the int * @see #toByteArrayOutputStream(Serializable) * @see java.io.ByteArrayOutputStream#size() */ public static int size(Serializable serializable) { ByteArrayOutputStream byteArrayOutputStream = null; try { byteArrayOutputStream = toByteArrayOutputStream(serializable); return byteArrayOutputStream.size(); } finally { IOUtils.closeQuietly(byteArrayOutputStream); } }
From source file:com.ibasco.agql.examples.base.BaseExample.java
private static byte[] padNullBytes(String text) { if (StringUtils.isEmpty(text)) return null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {/*from w ww. j a v a 2 s . c o m*/ bos.write(text.getBytes("UTF-8")); while ((bos.size() % 16) != 0) { bos.write(0); } } catch (IOException e) { throw new AsyncGameLibUncheckedException(e); } return bos.toByteArray(); }
From source file:org.apache.james.postage.mail.MailMatchingUtils.java
public static int getMimePartSize(MimeMultipart parts, String mimeType) { if (parts != null) { try {/*from w w w .jav a2 s. c o m*/ for (int i = 0; i < parts.getCount(); i++) { BodyPart bodyPart = parts.getBodyPart(i); if (bodyPart.getContentType().startsWith(mimeType)) { try { Object content = bodyPart.getContent(); if (content instanceof InputStream) { ByteArrayOutputStream os = new ByteArrayOutputStream(); IOUtils.copy(((InputStream) content), os); return os.size(); } else if (content instanceof String) { return ((String) content).length(); } else { throw new IllegalStateException( "Unsupported content: " + content.getClass().toString()); } } catch (IOException e) { throw new IllegalStateException("Unexpected IOException in getContent()"); } } } } catch (MessagingException e) { log.info("failed to process body parts.", e); } } return 0; }
From source file:net.seleucus.wsp.crypto.FwknopSymmetricCrypto.java
protected static byte[][] deriveKeyAndIV(byte[] salt, byte[] master_key) throws NoSuchAlgorithmException, IOException { byte[] key = new byte[KEY_LEN]; byte[] IV = new byte[IV_LEN]; MessageDigest md5 = MessageDigest.getInstance("MD5"); ByteArrayOutputStream data = new ByteArrayOutputStream(); ByteArrayOutputStream toHash = new ByteArrayOutputStream(); byte[] d = null; while (data.size() < IV_LEN + KEY_LEN) { md5.reset();/*from w ww .ja v a 2 s .c om*/ toHash.reset(); if (d != null) toHash.write(d); toHash.write(master_key); toHash.write(salt); d = md5.digest(toHash.toByteArray()); data.write(d); } byte[] output = data.toByteArray(); System.arraycopy(output, 0, key, 0, KEY_LEN); System.arraycopy(output, KEY_LEN, IV, 0, IV_LEN); return new byte[][] { key, IV }; }
From source file:Main.java
protected static byte[] getWapTextString(ByteArrayInputStream bais) { assert (null != bais); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int temp = bais.read(); assert (-1 != temp); while ((-1 != temp) && ('\0' != temp)) { if (isText(temp)) { bos.write(temp);/* w ww .j a va 2s. c o m*/ } temp = bais.read(); assert (-1 != temp); } if (bos.size() > 0) { return bos.toByteArray(); } return null; }
From source file:brickhouse.udf.bloom.BloomFactory.java
public static Filter ReadBloomFromStream(InputStream stream) throws IOException { /// Need to UUDecode first, /// TODO - read bytes directly when hive handles byte arrays better ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] bufferArr = new byte[4096]; int len = 0;/* w w w . j a v a 2 s. c o m*/ while ((len = stream.read(bufferArr, 0, 4096)) > 0) { buffer.write(bufferArr, 0, len); } if (buffer.size() == 0) { return BloomFactory.NewBloomInstance(); } return ReadBloomFromString(new String(buffer.toByteArray())); }
From source file:com.tingtingapps.securesms.mms.LegacyMmsConnection.java
protected static byte[] parseResponse(InputStream is) throws IOException { InputStream in = new BufferedInputStream(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Util.copy(in, baos);/* ww w . j a va 2 s.c om*/ Log.w(TAG, "Received full server response, " + baos.size() + " bytes"); return baos.toByteArray(); }