List of usage examples for java.io BufferedInputStream BufferedInputStream
public BufferedInputStream(InputStream in)
BufferedInputStream
and saves its argument, the input stream in
, for later use. From source file:com.arellomobile.android.push.utils.NetworkUtils.java
public static NetworkResult makeRequest(Map<String, Object> data, String methodName) throws Exception { NetworkResult result = new NetworkResult(500, null); OutputStream connectionOutput = null; InputStream inputStream = null; try {/*w ww .j av a 2 s.c om*/ String urlString = NetworkUtils.BASE_URL + methodName; if (useSSL) urlString = NetworkUtils.BASE_URL_SECURE + methodName; URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); connection.setDoOutput(true); JSONObject innerRequestJson = new JSONObject(); for (String key : data.keySet()) { innerRequestJson.put(key, data.get(key)); } JSONObject requestJson = new JSONObject(); requestJson.put("request", innerRequestJson); connection.setRequestProperty("Content-Length", String.valueOf(requestJson.toString().getBytes().length)); connectionOutput = connection.getOutputStream(); connectionOutput.write(requestJson.toString().getBytes()); connectionOutput.flush(); connectionOutput.close(); inputStream = new BufferedInputStream(connection.getInputStream()); ByteArrayOutputStream dataCache = new ByteArrayOutputStream(); // Fully read data byte[] buff = new byte[1024]; int len; while ((len = inputStream.read(buff)) >= 0) { dataCache.write(buff, 0, len); } // Close streams dataCache.close(); String jsonString = new String(dataCache.toByteArray()).trim(); Log.w(TAG, "PushWooshResult: " + jsonString); JSONObject resultJSON = new JSONObject(jsonString); result.setData(resultJSON); result.setCode(resultJSON.getInt("status_code")); } finally { if (null != inputStream) { inputStream.close(); } if (null != connectionOutput) { connectionOutput.close(); } } return result; }
From source file:fr.noop.subtitle.stl.StlParser.java
public StlObject parse(InputStream is, boolean strict) throws SubtitleParsingException, InvalidTimeRangeException { BufferedInputStream bis = new BufferedInputStream(is); DataInputStream dis = new DataInputStream(bis); // Create STL subtitle StlObject stl;//ww w . jav a 2 s.com try { // Read GSI block StlGsi gsi = this.readGsi(dis); stl = new StlObject(gsi); } catch (IOException e) { throw new SubtitleParsingException("Unable to parse Gsi block"); } // Iterate over all TTI blocks and parse them int subtitleIndex = 0; while (subtitleIndex++ < stl.getGsi().getTnb()) { StlTti tti; try { tti = this.readTti(dis, stl.getGsi()); } catch (IOException e) { throw new SubtitleParsingException("Unable to parse tti block"); } stl.addTti(tti); } return stl; }
From source file:edu.jhu.hlt.acute.iterators.tar.TarArchiveEntryByteIterator.java
/** * Create this object based on a {@link Path}. * * @throws IOException/*from www.j av a 2s . co m*/ */ public TarArchiveEntryByteIterator(Path path) throws IOException { this(new BufferedInputStream(Files.newInputStream(path))); }
From source file:com.milaboratory.core.io.CompressionType.java
private static InputStream createInputStream(CompressionType ct, InputStream is, int buffer) throws IOException { switch (ct) { case None:/* w ww . j av a 2 s . c om*/ return is; case GZIP: return new GZIPInputStream(is, buffer); case BZIP2: CompressorStreamFactory factory = new CompressorStreamFactory(); try { return factory.createCompressorInputStream(CompressorStreamFactory.BZIP2, new BufferedInputStream(is)); } catch (CompressorException e) { throw new IOException(e); } } throw new NullPointerException(); }
From source file:cc.aileron.commons.resource.ResourceImpl.java
/** * @return byte[]// ww w .ja v a2 s . com * @throws IOException */ @Override public byte[] toBytes() throws IOException { final BufferedInputStream in = new BufferedInputStream(content.getInputStream()); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream os = new DataOutputStream(baos); byte[] buffer = new byte[8192]; while (in.read(buffer) != -1) { os.write(buffer); buffer = new byte[8192]; } return baos.toByteArray(); }
From source file:com.hs.mail.util.FileUtils.java
public static void compress(File srcFile, File destFile) throws IOException { InputStream input = null;/*from w w w . j a va 2s. c o m*/ OutputStream output = null; try { input = new BufferedInputStream(new FileInputStream(srcFile)); output = new GZIPOutputStream(new FileOutputStream(destFile)); IOUtils.copyLarge(input, output); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(input); } }
From source file:net.jotel.ws.client.WebSocketReaderThread.java
public WebSocketReaderThread(WebSocketClient wsClient) throws WebSocketException { super("WebSocket Reader Thread"); setDaemon(true);/*from w w w . jav a2 s .c om*/ this.wsClient = wsClient; inputStream = new BufferedInputStream(wsClient.getInputStream()); }
From source file:edu.dfci.cccb.mev.limma.domain.simple.FileBackedLimma.java
@SneakyThrows public static FileBackedLimma from(InputStream results) { FileBackedLimma result = new FileBackedLimma(new TemporaryFolder()); try (OutputStream full = new BufferedOutputStream(new FileOutputStream(result.full)); BufferedInputStream in = new BufferedInputStream(results)) { IOUtils.copy(in, full);//from ww w.j av a 2 s. c o m } return result; }
From source file:com.textocat.textokit.commons.wfstore.SharedDefaultWordformStore.java
@SuppressWarnings("unchecked") @Override/*from ww w .j a va2 s. c om*/ public void load(DataResource dr) throws ResourceInitializationException { DefaultWordformStore<TagType> ws; try { ws = (DefaultWordformStore<TagType>) SerializationUtils .deserialize(new BufferedInputStream(dr.getInputStream())); } catch (IOException e) { throw new ResourceInitializationException(e); } this.strKeyMap = ws.strKeyMap; this.metadataMap = ws.metadataMap; }
From source file:com.useekm.types.AbstractGeo.java
public static byte[] gunzip(byte[] bytes) { try {/*from ww w . j av a 2 s. c o m*/ ByteArrayInputStream bis = new ByteArrayInputStream(bytes); BufferedInputStream bufis = new BufferedInputStream(new GZIPInputStream(bis)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int len; while ((len = bufis.read(buf)) > 0) bos.write(buf, 0, len); byte[] result = bos.toByteArray(); bufis.close(); bos.close(); return result; } catch (IOException e) { throw new IllegalStateException("Unexpected IOException on inmemory gunzip", e); } }