List of usage examples for java.io BufferedInputStream close
public void close() throws IOException
From source file:edu.harvard.i2b2.eclipse.plugins.metadataLoader.util.FileUtil.java
public static void download(String workingDir, String URL, String filename) throws IOException { workingDir = workingDir + filename;/*ww w.ja v a 2 s . c om*/ DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(URL); HttpResponse response = httpclient.execute(httpget); // System.out.println(response.getStatusLine()); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); try { BufferedInputStream bis = new BufferedInputStream(instream); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(workingDir))); int inByte; while ((inByte = bis.read()) != -1) { bos.write(inByte); } bis.close(); bos.close(); // unzip("ICD10.zip"); } catch (IOException ex) { throw ex; } catch (RuntimeException ex) { httpget.abort(); throw ex; } finally { instream.close(); } httpclient.getConnectionManager().shutdown(); } }
From source file:Main.java
public static boolean prepareDex(Context context, File dexInternalStoragePath, String dexFile) { BufferedInputStream bis = null; OutputStream dexWriter = null; try {/*from w w w. ja v a 2 s . com*/ bis = new BufferedInputStream(context.getAssets().open(dexFile)); dexWriter = new BufferedOutputStream(new FileOutputStream(dexInternalStoragePath)); byte[] buf = new byte[BUF_SIZE]; int len; while ((len = bis.read(buf, 0, BUF_SIZE)) > 0) { dexWriter.write(buf, 0, len); } dexWriter.close(); bis.close(); return true; } catch (IOException e) { if (dexWriter != null) { try { dexWriter.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } if (bis != null) { try { bis.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } return false; } }
From source file:com.dc.util.file.FileSupport.java
public static void writeBinaryFile(InputStream in, File targetFile) throws IOException { BufferedInputStream bis = null; BufferedOutputStream bos = null; try {/*from w w w .ja v a2s . co m*/ bis = new BufferedInputStream(in); bos = new BufferedOutputStream(new FileOutputStream(targetFile)); copyStream(bis, bos); } finally { if (bis != null) { bis.close(); } if (bos != null) { bos.close(); } } }
From source file:Main.java
public static void compressAFileToZip(File zip, File source) throws IOException { Log.d("source: " + source.getAbsolutePath(), ", length: " + source.length()); Log.d("zip:", zip.getAbsolutePath()); zip.getParentFile().mkdirs();// w w w. j a v a 2 s. com File tempFile = new File(zip.getAbsolutePath() + ".tmp"); FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos); ZipOutputStream zos = new ZipOutputStream(bos); ZipEntry zipEntry = new ZipEntry(source.getName()); zipEntry.setTime(source.lastModified()); zos.putNextEntry(zipEntry); FileInputStream fis = new FileInputStream(source); BufferedInputStream bis = new BufferedInputStream(fis); byte[] bArr = new byte[4096]; int byteRead = 0; while ((byteRead = bis.read(bArr)) != -1) { zos.write(bArr, 0, byteRead); } zos.flush(); zos.closeEntry(); zos.close(); Log.d("zipEntry: " + zipEntry, "compressedSize: " + zipEntry.getCompressedSize()); bos.flush(); fos.flush(); bos.close(); fos.close(); bis.close(); fis.close(); zip.delete(); tempFile.renameTo(zip); }
From source file:Main.java
/** * Creates <code>TrustAnchor</code> instance * constructed using self signed test certificate * * @return <code>TrustAnchor</code> instance *//*from www. j a v a 2s . c o m*/ public static TrustAnchor getTrustAnchor() { CertificateFactory cf = null; try { cf = CertificateFactory.getInstance(certType); } catch (CertificateException e) { // requested cert type is not available in the // default provider package or any of the other provider packages // that were searched throw new RuntimeException(e); } BufferedInputStream bis = null; try { bis = new BufferedInputStream(new ByteArrayInputStream(getEncodedX509Certificate())); X509Certificate c1 = (X509Certificate) cf.generateCertificate(bis); return new TrustAnchor(c1, null); } catch (Exception e) { // all failures are fatal throw new RuntimeException(e); } finally { if (bis != null) { try { bis.close(); } catch (IOException ign) { } } } }
From source file:Main.java
public static void copyFile(File sourceFile, File targetFile) throws IOException { BufferedInputStream inBuff = null; BufferedOutputStream outBuff = null; try {/* w ww .ja va 2 s.c om*/ inBuff = new BufferedInputStream(new FileInputStream(sourceFile)); outBuff = new BufferedOutputStream(new FileOutputStream(targetFile)); byte[] buffer = new byte[BUFFER]; int length; while ((length = inBuff.read(buffer)) != -1) { outBuff.write(buffer, 0, length); } outBuff.flush(); } finally { if (inBuff != null) { inBuff.close(); } if (outBuff != null) { outBuff.close(); } } }
From source file:com.dc.util.file.FileSupport.java
public static void writeBinaryFile(File inputFile, File outputFile) throws IOException { BufferedInputStream bis = null; BufferedOutputStream bos = null; try {// w ww . j a va 2 s.c om bis = new BufferedInputStream(new FileInputStream(inputFile)); bos = new BufferedOutputStream(new FileOutputStream(outputFile)); copyStream(bis, bos); } finally { if (bis != null) { bis.close(); } if (bos != null) { bos.close(); } } }
From source file:FacebookImageLoader.java
public static BitmapFactory.Options getImageSizeFromFile(final String file) { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true;//from w w w. j a va 2 s . c om // With inJustDecodeBounds set, we're just going to peek at // the resolution of the image. try { BufferedInputStream is = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE); BitmapFactory.decodeStream(is, null, opts); is.close(); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } catch (OutOfMemoryError e) { e.printStackTrace(); return null; } return opts; }
From source file:com.github.pitzcarraldo.openjpeg.OpenJPEGLoader.java
private static void copyStreamToFile(InputStream pInputStream, File pFile) throws IOException { BufferedInputStream bis = new BufferedInputStream(pInputStream); FileOutputStream fos = new FileOutputStream(pFile.getAbsolutePath()); byte[] buffer = new byte[32768]; int bytesRead = 0; while (bis.available() > 0) { bytesRead = bis.read(buffer);//from w ww . jav a 2s . c o m fos.write(buffer, 0, bytesRead); } bis.close(); fos.close(); pFile.deleteOnExit(); }
From source file:jenkins.uvision.CoverageParser.java
public static TestRun parse(File inFile) throws IOException { FileInputStream fileInputStream = null; BufferedInputStream bufferedInputStream = null; try {//from w ww . j av a2 s. c om fileInputStream = new FileInputStream(inFile); bufferedInputStream = new BufferedInputStream(fileInputStream); CoverageParser parser = new CoverageParser(); TestRun result = parse(bufferedInputStream); if (result == null) throw new NullPointerException(); return result; } finally { try { if (bufferedInputStream != null) bufferedInputStream.close(); if (fileInputStream != null) fileInputStream.close(); } catch (IOException e) { } } }