List of usage examples for java.io FileOutputStream close
public void close() throws IOException
From source file:Main.java
public static void saveSeriObj(Context context, String fileName, Object o) throws Exception { String path = context.getFilesDir() + "/"; File dir = new File(path); dir.mkdirs();//from w w w.java 2 s . c o m File f = new File(dir, fileName); if (f.exists()) { f.delete(); } FileOutputStream os = new FileOutputStream(f); ObjectOutputStream objectOutputStream = new ObjectOutputStream(os); objectOutputStream.writeObject(o); objectOutputStream.close(); os.close(); }
From source file:Main.java
@Deprecated private static void copy(InputStream in, File dst) throws IOException { FileOutputStream out = new FileOutputStream(dst); byte[] buf = new byte[1024]; int len;//from ww w .j a v a2 s . c o m while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
private static void saveStream(InputStream is, String savePath) throws IOException { FileOutputStream output = new FileOutputStream(savePath); int readlen;/* w w w. j a v a 2s . c o m*/ byte[] buf = new byte[BUFF_SIZE]; while ((readlen = is.read(buf)) > 0) { output.write(buf, 0, readlen); } output.close(); }
From source file:com.streamsets.datacollector.util.UntarUtility.java
/** * Ungzip an input file into an output file. * <p>/*from w w w .j a v a 2 s.co m*/ * The output file is created in the output folder, having the same name as the input file, minus the '.gz' extension. * @param inputFile the input .gz file * @param outputDir the output directory file. * @throws IOException * @throws FileNotFoundException * @return The {@File} with the ungzipped content. * @throws ArchiveException */ public static List<File> unGzip(final File inputFile, final File outputDir) throws FileNotFoundException, IOException, ArchiveException { LOG.info(String.format("Ungzipping %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath())); final File outputFile = new File(outputDir, inputFile.getName().substring(0, inputFile.getName().length() - 3)); final GZIPInputStream in = new GZIPInputStream(new FileInputStream(inputFile)); final FileOutputStream out = new FileOutputStream(outputFile); IOUtils.copy(in, out); in.close(); out.close(); return unTar(outputFile, outputDir); }
From source file:Main.java
public static void writeBuffer2InternalStorage(String path, byte[] data) { File file = new File(_context.getFilesDir() + File.separator + path); try {/*from w w w . ja va 2 s . c o m*/ FileOutputStream outstream; if (!file.exists()) { file.createNewFile(); } outstream = new FileOutputStream(file); outstream.write(data); outstream.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:gov.nasa.ensemble.dictionary.nddl.ModelGenerator.java
public static boolean generateModel(EActivityDictionary ad) throws IOException { FileOutputStream streams[] = makeModelOutputStreams(); ParseInterpreter parseInterpreter = parseInterpret(ad); parseInterpreter.writeObjects(streams[0]); parseInterpreter.writeCompats(streams[1], OBJECTS_NDDL); parseInterpreter.writeInitialState(streams[2], MODEL_NDDL); for (FileOutputStream stream : streams) stream.close(); // Put all model-related files in the required location relocateModelFiles();/*from w w w . j a va2 s . c o m*/ return true; }
From source file:Main.java
public static void readAsFile(InputStream inSream, File file) throws Exception { FileOutputStream outStream = new FileOutputStream(file); byte[] buffer = new byte[1024]; int len = -1; while ((len = inSream.read(buffer)) != -1) { outStream.write(buffer, 0, len); }//from ww w. jav a 2 s. com outStream.close(); inSream.close(); }
From source file:net.ontopia.utils.EncryptionUtils.java
/** * INTERNAL: Reads the file into memory, encrypting it in the * process, then writes the encrypted data back out to the file. *//*from w w w. j av a 2 s.com*/ public static void encrypt(File file) throws IOException { FileInputStream in = new FileInputStream(file); ByteArrayOutputStream tmpout = new ByteArrayOutputStream(); encrypt(in, tmpout); in.close(); FileOutputStream out = new FileOutputStream(file); ByteArrayInputStream src = new ByteArrayInputStream(tmpout.toByteArray()); IOUtils.copy(src, out); out.close(); }
From source file:com.siva.javamultithreading.MultiThreadExecutor.java
protected static void writeFile(HSSFWorkbook book, FileOutputStream out) throws Exception { // FileOutputStream out = new FileOutputStream(file); book.write(out);//from w w w. ja v a 2 s . c o m out.close(); }
From source file:eu.planets_project.services.datatypes.Content.java
/** * Create (streamed) content by reference, from an input stream. * @param inputStream The InputStream containing the value for the content. * @return A content instance with the specified value *//* ww w. j ava 2 s. c o m*/ public static DigitalObjectContent byReference(final InputStream inputStream) { try { File tempFile = File.createTempFile("tempContent", "tmp"); tempFile.deleteOnExit(); // TODO do we really want this here? FileOutputStream out = new FileOutputStream(tempFile); IOUtils.copyLarge(inputStream, out); out.close(); return new ImmutableContent(tempFile); } catch (IOException e) { e.printStackTrace(); } throw new IllegalStateException("Could not create content for input stream: " + inputStream); }