List of usage examples for com.liferay.portal.kernel.io.unsync UnsyncByteArrayOutputStream write
@Override public void write(byte[] bytes, int offset, int length)
From source file:com.liferay.util.transport.MulticastDatagramHandler.java
License:Open Source License
protected byte[] getUnzippedBytes(byte[] bytes) throws Exception { InputStream is = new GZIPInputStream(new UnsyncByteArrayInputStream(bytes)); UnsyncByteArrayOutputStream ubaos = new UnsyncByteArrayOutputStream(bytes.length); byte[] buffer = new byte[1500]; int c = 0;/*from ww w .j ava 2 s.co m*/ while (true) { if (c == -1) { break; } c = is.read(buffer, 0, 1500); if (c != -1) { ubaos.write(buffer, 0, c); } } is.close(); ubaos.flush(); ubaos.close(); return ubaos.toByteArray(); }
From source file:com.twelve.capital.external.feed.util.HttpImpl.java
License:Open Source License
/** * This method only uses the default Commons HttpClient implementation when * the URL object represents a HTTP resource. The URL object could also * represent a file or some JNDI resource. In that case, the default Java * implementation is used.//from www. java 2s.c om * * @param url the URL * @return A string representation of the resource referenced by the URL * object * @throws IOException if an IO exception occurred */ @Override public String URLtoString(URL url) throws IOException { String xml = null; if (url == null) { return null; } String protocol = StringUtil.toLowerCase(url.getProtocol()); if (protocol.startsWith(Http.HTTP) || protocol.startsWith(Http.HTTPS)) { return URLtoString(url.toString()); } URLConnection urlConnection = url.openConnection(); InputStream inputStream = urlConnection.getInputStream(); UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(); byte[] bytes = new byte[512]; for (int i = inputStream.read(bytes, 0, 512); i != -1; i = inputStream.read(bytes, 0, 512)) { unsyncByteArrayOutputStream.write(bytes, 0, i); } xml = new String(unsyncByteArrayOutputStream.unsafeGetByteArray(), 0, unsyncByteArrayOutputStream.size()); inputStream.close(); unsyncByteArrayOutputStream.close(); return xml; }