List of usage examples for java.io BufferedOutputStream close
@Override public void close() throws IOException
From source file:com.haru.ui.image.workers.MediaProcessorThread.java
protected void processContentProviderMedia(String path, String extension) throws Exception { checkExtension(Uri.parse(path));//w w w.ja v a2 s .c o m try { InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse(path)); filePath = foldername + File.separator + Calendar.getInstance().getTimeInMillis() + extension; BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] buf = new byte[2048]; int len; while ((len = inputStream.read(buf)) > 0) { outStream.write(buf, 0, len); } inputStream.close(); outStream.close(); process(); } catch (FileNotFoundException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:com.cars.manager.utils.imageChooser.threads.MediaProcessorThread.java
protected void processPicasaMedia(String path, String extension) throws Exception { if (Config.DEBUG) { Log.i(TAG, "Picasa Started"); }/* ww w.jav a2 s. co m*/ try { InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse(path)); filePath = FileUtils.getDirectory(foldername) + File.separator + Calendar.getInstance().getTimeInMillis() + extension; BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] buf = new byte[2048]; int len; while ((len = inputStream.read(buf)) > 0) { outStream.write(buf, 0, len); } inputStream.close(); outStream.close(); process(); } catch (FileNotFoundException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } if (Config.DEBUG) { Log.i(TAG, "Picasa Done"); } }
From source file:com.haru.ui.image.workers.MediaProcessorThread.java
protected void processPicasaMedia(String path, String extension) throws Exception { if (/* TODO: DEBUG */ true) { Log.i(TAG, "Picasa Started"); }/*from w ww . java2s . com*/ try { InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse(path)); filePath = foldername + File.separator + Calendar.getInstance().getTimeInMillis() + extension; BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] buf = new byte[2048]; int len; while ((len = inputStream.read(buf)) > 0) { outStream.write(buf, 0, len); } inputStream.close(); outStream.close(); process(); } catch (FileNotFoundException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } if (/* TODO: DEBUG */ true) { Log.i(TAG, "Picasa Done"); } }
From source file:com.cars.manager.utils.imageChooser.threads.MediaProcessorThread.java
protected void processGooglePhotosMedia(String path, String extension) throws Exception { if (Config.DEBUG) { Log.i(TAG, "Google photos Started"); Log.i(TAG, "URI: " + path); Log.i(TAG, "Extension: " + extension); }// ww w . j a va2 s . c o m String retrievedExtension = checkExtension(Uri.parse(path)); if (retrievedExtension != null && !TextUtils.isEmpty(retrievedExtension)) { extension = "." + retrievedExtension; } try { filePath = FileUtils.getDirectory(foldername) + File.separator + Calendar.getInstance().getTimeInMillis() + extension; ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver() .openFileDescriptor(Uri.parse(path), "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); InputStream inputStream = new FileInputStream(fileDescriptor); BufferedInputStream reader = new BufferedInputStream(inputStream); BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] buf = new byte[2048]; int len; while ((len = reader.read(buf)) > 0) { outStream.write(buf, 0, len); } outStream.flush(); outStream.close(); inputStream.close(); process(); } catch (FileNotFoundException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } if (Config.DEBUG) { Log.i(TAG, "Picasa Done"); } }
From source file:com.ibm.amc.resources.TemporaryFileResource.java
/** * Write an InputStream to a local file//from www. ja va 2 s . c o m * * @param stream * contains the file * @return a File object from the input stream * @throws IOException */ private File writeToFile(InputStream stream) throws IOException { if (logger.isEntryEnabled()) logger.entry("writeToFile", stream); File file = FileManager.createUploadFile(); BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(stream); out = new BufferedOutputStream(new FileOutputStream(file)); IOUtils.copy(in, out); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.error("ERROR: IOException thrown attempting to close the input stream", e); } } if (out != null) { try { out.close(); } catch (IOException e) { logger.error("ERROR: IOException thrown attempting to close the output stream", e); } } } if (logger.isEntryEnabled()) logger.exit("writeToFile", file); return file; }
From source file:com.android.volley.toolbox.DiskBasedCache.java
/** * Puts the entry with the specified key into the cache. */// ww w . ja va2 s. c o m @Override public synchronized void put(String key, Entry entry) { pruneIfNeeded(entry.data.length); File file = getFileForKey(key); try { BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(file)); CacheHeader e = new CacheHeader(key, entry); boolean success = e.writeHeader(fos); if (!success) { fos.close(); VolleyLog.d("Failed to write header for %s", file.getAbsolutePath()); throw new IOException(); } fos.write(entry.data); fos.close(); putEntry(key, e); return; } catch (IOException e) { } boolean deleted = file.delete(); if (!deleted) { VolleyLog.d("Could not clean up file %s", file.getAbsolutePath()); } }
From source file:com.haru.ui.image.workers.MediaProcessorThread.java
protected void processGooglePhotosMedia(String path, String extension) throws Exception { if (/* TODO: DEBUG */ true) { Log.i(TAG, "Google photos Started"); Log.i(TAG, "URI: " + path); Log.i(TAG, "Extension: " + extension); }/* www.j ava2 s . c om*/ String retrievedExtension = checkExtension(Uri.parse(path)); if (retrievedExtension != null && !TextUtils.isEmpty(retrievedExtension)) { extension = "." + retrievedExtension; } try { filePath = foldername + File.separator + Calendar.getInstance().getTimeInMillis() + extension; ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver() .openFileDescriptor(Uri.parse(path), "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); InputStream inputStream = new FileInputStream(fileDescriptor); BufferedInputStream reader = new BufferedInputStream(inputStream); BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] buf = new byte[2048]; int len; while ((len = reader.read(buf)) > 0) { outStream.write(buf, 0, len); } outStream.flush(); outStream.close(); inputStream.close(); process(); } catch (FileNotFoundException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } if (/* TODO: DEBUG */ true) { Log.i(TAG, "Picasa Done"); } }
From source file:com.nokia.carbide.installpackages.InstallPackages.java
private URL getAvailablePackagesURL() throws Exception { URL url = null;/*from ww w . j ava2 s . co m*/ // see if the file is local (Ed's hack for testing...) String masterFilePathStr = getMasterFilePath(); url = new URL(masterFilePathStr); if (url.getProtocol().equals("file")) { return url; } // else, read the file to a local temporary location GetMethod getMethod = new GetMethod(masterFilePathStr); HttpClient client = new HttpClient(); setProxyData(client, getMethod); client.getHttpConnectionManager().getParams().setConnectionTimeout(8000); int serverStatus = 0; byte[] responseBody; try { serverStatus = client.executeMethod(getMethod); responseBody = getMethod.getResponseBody(); } catch (Exception e) { // could be HttpException or IOException throw new Exception(e); } finally { getMethod.releaseConnection(); } // HTTP status codes: 2xx = Success if (serverStatus >= 200 && serverStatus < 300) { File tempDir = FileUtils.getTemporaryDirectory(); IPath path = new Path(tempDir.getAbsolutePath()); IPath masterFilePath = path.append(getMasterFileName()); File masterFile = masterFilePath.toFile(); if (masterFile.exists()) masterFile.delete(); FileOutputStream fos = new FileOutputStream(masterFile); BufferedOutputStream out = new BufferedOutputStream(fos); ByteArrayInputStream in = new ByteArrayInputStream(responseBody); boolean foundOpenBrace = false; int c; while ((c = in.read()) != -1) { if (c == '<') foundOpenBrace = true; if (foundOpenBrace) out.write(c); } out.close(); in.close(); url = masterFile.toURI().toURL(); return url; } return null; }
From source file:de.thorstenberger.taskmodel.complex.complextaskdef.impl.ComplexTaskDefDAOImpl.java
public void save(ComplexTaskDefRoot ctdr, OutputStream os) throws TaskApiException { BufferedOutputStream bos = new BufferedOutputStream(os); Marshaller marshaller = null; try {/*from w w w . j ava 2 s. c o m*/ JAXBContext jc = createJAXBContext(); marshaller = JAXBUtils.getJAXBMarshaller(jc); Validator validator = jc.createValidator(); ComplexTaskDef ctd = ((ComplexTaskDefRootImpl) ctdr).getJAXBContent(); validator.validate(ctd); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true)); marshaller.marshal(ctd, bos); } catch (JAXBException e) { throw new TaskModelPersistenceException(e); } finally { try { bos.close(); } catch (IOException e) { throw new TaskModelPersistenceException(e); } if (marshaller != null) JAXBUtils.releaseJAXBMarshaller(jc, marshaller); } }