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.wishlist.Utility.java
public static Bitmap getBitmap(String url) { Bitmap bm = null;/*from w ww . ja va 2s . co m*/ try { URL aURL = new URL(url); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm = BitmapFactory.decodeStream(new FlushedInputStream(is)); bis.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (httpclient != null) { httpclient.close(); } } return bm; }
From source file:de.fanero.uncompress.stream.BufferedArchiveInputStream.java
public BufferedArchiveInputStream(ArchiveInputStream archiveInputStream) { this.archiveInputStream = archiveInputStream; this.buffered = new BufferedInputStream(archiveInputStream); }
From source file:gov.nih.nci.nbia.textsupport.NCIADicomTextObject.java
public static List<DicomTagDTO> getTagElements(File file) throws Exception { DcmParserFactory pFact = DcmParserFactory.getInstance(); DcmObjectFactory oFact = DcmObjectFactory.getInstance(); BufferedInputStream in = null; List<DicomTagDTO> allElements = new ArrayList<DicomTagDTO>(); try {/* www . j av a2 s . c om*/ in = new BufferedInputStream(new FileInputStream(file)); DcmParser parser = pFact.newDcmParser(in); FileFormat fileFormat = parser.detectFileFormat(); if (fileFormat == null) { throw new IOException("Unrecognized file format: " + file); } Dataset dataset = oFact.newDataset(); parser.setDcmHandler(dataset.getDcmHandler()); //Parse the file, but don't get the pixels in order to save heap space parser.parseDcmFile(fileFormat, Tags.PixelData); //See if this is a real image. boolean isImage = (parser.getReadTag() == Tags.PixelData); //Get the charset in case we need it for manifest processing. in.close(); SpecificCharacterSet cs = dataset.getSpecificCharacterSet(); allElements.addAll(walkDataset(dataset.getFileMetaInfo(), cs, "")); allElements.addAll(walkDataset(dataset, cs, "")); parser = null; } catch (Exception exception) { if (in != null) { in.close(); } throw exception; } return allElements; }
From source file:com.mirth.connect.connectors.tcp.StateAwareSocket.java
@Override public InputStream getInputStream() throws IOException { if (bis == null) { bis = new BufferedInputStream(super.getInputStream()); }//from ww w .j av a 2s. co m return bis; }
From source file:de.innovationgate.wgpublisher.design.OverlayData.java
public static OverlayData load(FileObject overlayDataFile) throws Exception { InputStream in = new BufferedInputStream(overlayDataFile.getContent().getInputStream()); OverlayData overlayData = OverlayData.read(in); in.close();//from ww w . jav a 2s .co m return overlayData; }
From source file:edu.dfci.cccb.mev.deseq.domain.simple.FileBackedDESeq.java
@SneakyThrows public static FileBackedDESeq from(InputStream results) { FileBackedDESeq result = new FileBackedDESeq(new TemporaryFolder()); try (OutputStream full = new BufferedOutputStream(new FileOutputStream(result.full)); BufferedInputStream in = new BufferedInputStream(results)) { IOUtils.copy(in, full);/*from w w w .ja va2s. c o m*/ } return result; }
From source file:edu.du.penrose.systems.util.HttpClientUtils.java
/** * Appends response form URL to a StringBuffer * //from w ww.ja v a 2 s . c o m * @param requestUrl * @param resultStringBuffer * @return int request status code OR -1 if an exception occurred */ static public int getAsString(String requestUrl, StringBuffer resultStringBuffer) { HttpClient client = new HttpClient(); // client.getState().setCredentials( // new AuthScope("localhost", 7080, null ), // new UsernamePasswordCredentials("nation", "nationPW") // ); // client.getParams().setAuthenticationPreemptive(true); HttpMethod method = new GetMethod(requestUrl); // method.setDoAuthentication( true ); // client.getParams().setAuthenticationPreemptive(true); // Execute and print response try { client.executeMethod(method); InputStream is = method.getResponseBodyAsStream(); BufferedInputStream bis = new BufferedInputStream(is); String datastr = null; byte[] bytes = new byte[8192]; // reading as chunk of 8192 bytes int count = bis.read(bytes); while (count != -1 && count <= 8192) { datastr = new String(bytes, 0, count); resultStringBuffer.append(datastr); count = bis.read(bytes); } bis.close(); } catch (Exception e) { e.printStackTrace(); } finally { method.releaseConnection(); } return method.getStatusCode(); }
From source file:subhan.portal.config.Util.java
public static void downloadFromUrl(String downloadUrl, String fileName) throws IOException { File root = android.os.Environment.getExternalStorageDirectory(); // path ke sdcard File dir = new File(root.getAbsolutePath() + "/youread"); // path ke folder if (dir.exists() == false) { // cek folder eksistensi dir.mkdirs(); // kalau belum ada, dibuat }// w w w . j a v a 2 s .c o m URL url = new URL(downloadUrl); // you can write here any link File file = new File(dir, fileName); // Open a connection to that URL. URLConnection ucon = url.openConnection(); // Define InputStreams to read from the URLConnection. InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); // Read bytes to the Buffer until there is nothing more to read(-1). ByteArrayBuffer baf = new ByteArrayBuffer(5000); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } // Convert the Bytes read to a String. FileOutputStream fos = new FileOutputStream(file); fos.write(baf.toByteArray()); fos.flush(); fos.close(); }
From source file:net.ovres.util.UncompressedInputStream.java
public UncompressedInputStream(InputStream input) throws IOException { super(new BufferedInputStream(convertStream(input))); }
From source file:com.daphne.es.maintain.editor.web.controller.utils.CompressUtils.java
private static void addFilesToCompression(ZipArchiveOutputStream zaos, File file, String dir) throws IOException { ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(file, dir + file.getName()); zaos.putArchiveEntry(zipArchiveEntry); if (file.isFile()) { BufferedInputStream bis = null; try {/*from w ww.jav a 2 s. c o m*/ bis = new BufferedInputStream(new FileInputStream(file)); IOUtils.copy(bis, zaos); zaos.closeArchiveEntry(); } catch (IOException e) { throw e; } finally { IOUtils.closeQuietly(bis); } } else if (file.isDirectory()) { zaos.closeArchiveEntry(); for (File childFile : file.listFiles()) { addFilesToCompression(zaos, childFile, dir + file.getName() + File.separator); } } }