Java Code Examples for java.io.FileOutputStream#getFD()
The following examples show how to use
java.io.FileOutputStream#getFD() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestFileStreamWrappers.java From tracing-framework with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testFileStreamWrappers() throws IOException { File f = File.createTempFile("aspectjinput", "txt"); f.deleteOnExit(); FileOutputStream fos = new FileOutputStream(f); assertTrue(fos instanceof FileOutputStreamWrapper); FileOutputStream fos2 = new FileOutputStream(f.getAbsolutePath()); assertTrue(fos2 instanceof FileOutputStreamWrapper); FileOutputStream fos3 = new FileOutputStream(fos.getFD()); assertTrue(fos3 instanceof FileOutputStreamWrapper); fos.write(5); fos.close(); FileInputStream fis = new FileInputStream(f); assertTrue(fis instanceof FileInputStreamWrapper); FileInputStream fis2 = new FileInputStream(f.getAbsolutePath()); assertTrue(fis2 instanceof FileInputStreamWrapper); FileInputStream fis3 = new FileInputStream(fis.getFD()); assertTrue(fis3 instanceof FileInputStreamWrapper); }
Example 2
Source File: FileUtils.java From dttv-android with GNU General Public License v3.0 | 6 votes |
/** * Copies bytes from the URL <code>source</code> to a file * <code>destination</code>. The directories up to <code>destination</code> * will be created if they don't already exist. <code>destination</code> * will be overwritten if it already exists. * * @param source the <code>URL</code> to copy bytes from, must not be <code>null</code> * @param destination the non-directory <code>File</code> to write bytes to * (possibly overwriting), must not be <code>null</code> * @throws IOException if <code>source</code> URL cannot be opened * @throws IOException if <code>destination</code> is a directory * @throws IOException if <code>destination</code> cannot be written * @throws IOException if <code>destination</code> needs creating but can't be * @throws IOException if an IO error occurs during copying */ public static void copyURLToFile(URL source, File destination) throws IOException { InputStream input = source.openStream(); try { FileOutputStream output = openOutputStream(destination); try { IOUtils.copy(input, output); FileDescriptor fd = output.getFD(); if(fd.valid()) fd.sync(); } finally { IOUtils.closeQuietly(output); } } finally { IOUtils.closeQuietly(input); } }
Example 3
Source File: FileUtils.java From dttv-android with GNU General Public License v3.0 | 6 votes |
/** * Copies bytes from the URL <code>source</code> to a file * <code>destination</code>. The directories up to <code>destination</code> * will be created if they don't already exist. <code>destination</code> * will be overwritten if it already exists. * * @param source the <code>URL</code> to copy bytes from, must not be <code>null</code> * @param destination the non-directory <code>File</code> to write bytes to * (possibly overwriting), must not be <code>null</code> * @throws IOException if <code>source</code> URL cannot be opened * @throws IOException if <code>destination</code> is a directory * @throws IOException if <code>destination</code> cannot be written * @throws IOException if <code>destination</code> needs creating but can't be * @throws IOException if an IO error occurs during copying */ public static void copyURLToFile(URL source, File destination) throws IOException { InputStream input = source.openStream(); try { FileOutputStream output = openOutputStream(destination); try { IOUtils.copy(input, output); FileDescriptor fd = output.getFD(); if(fd.valid()) fd.sync(); } finally { IOUtils.closeQuietly(output); } } finally { IOUtils.closeQuietly(input); } }
Example 4
Source File: FileIO.java From PHONK with GNU General Public License v3.0 | 5 votes |
/** * Write the data to the file indicate by fileName. The file is created if * it doesn't exists. */ public static void write(Activity activity, String data, String fileName) throws IOException { FileOutputStream fo = activity.openFileOutput(fileName, 0); BufferedWriter bf = new BufferedWriter(new FileWriter(fo.getFD())); bf.write(data); bf.flush(); bf.close(); }
Example 5
Source File: MediaMuxerWrapper.java From libcommon with Apache License 2.0 | 5 votes |
/** * 出力先をOutputStreamで指定するコンストラクタ * @param output * @param format */ @RequiresApi(api = Build.VERSION_CODES.O) public MediaMuxerWrapper( @NonNull final FileOutputStream output, final int format) throws IOException { mMuxer = new MediaMuxer(output.getFD(), format); mOutputStream = output; mOutputPath = null; // FIXME FileOutputStream生成時のファイルパスを代入したい }
Example 6
Source File: FileUtils.java From dttv-android with GNU General Public License v3.0 | 5 votes |
/** * Internal copy file method. * * @param srcFile the validated source file, must not be <code>null</code> * @param destFile the validated destination file, must not be <code>null</code> * @param preserveFileDate whether to preserve the file date * @throws IOException if an error occurs */ private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException { if (destFile.exists() && destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' exists but is a directory"); } FileInputStream input = new FileInputStream(srcFile); try { FileOutputStream output = new FileOutputStream(destFile); try { IOUtils.copy(input, output); FileDescriptor fd = output.getFD(); if(fd.valid()) fd.sync(); } finally { IOUtils.closeQuietly(output); } } finally { IOUtils.closeQuietly(input); } if (srcFile.length() != destFile.length()) { throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'"); } if (preserveFileDate) { destFile.setLastModified(srcFile.lastModified()); } }
Example 7
Source File: FileUtils.java From dttv-android with GNU General Public License v3.0 | 5 votes |
/** * Internal copy file method. * * @param srcFile the validated source file, must not be <code>null</code> * @param destFile the validated destination file, must not be <code>null</code> * @param preserveFileDate whether to preserve the file date * @throws IOException if an error occurs */ private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException { if (destFile.exists() && destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' exists but is a directory"); } FileInputStream input = new FileInputStream(srcFile); try { FileOutputStream output = new FileOutputStream(destFile); try { IOUtils.copy(input, output); FileDescriptor fd = output.getFD(); if(fd.valid()) fd.sync(); } finally { IOUtils.closeQuietly(output); } } finally { IOUtils.closeQuietly(input); } if (srcFile.length() != destFile.length()) { throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'"); } if (preserveFileDate) { destFile.setLastModified(srcFile.lastModified()); } }
Example 8
Source File: FileUtil.java From evosql with Apache License 2.0 | 4 votes |
FileSync(FileOutputStream os) throws IOException { outDescriptor = os.getFD(); }