本文整理了Java中java.io.FileOutputStream.getFD()
方法的一些代码示例,展示了FileOutputStream.getFD()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileOutputStream.getFD()
方法的具体详情如下:
包路径:java.io.FileOutputStream
类名称:FileOutputStream
方法名:getFD
[英]Returns the underlying file descriptor.
[中]返回基础文件描述符。
代码示例来源:origin: apache/flink
@Override
public void sync() throws IOException {
fos.getFD().sync();
}
代码示例来源:origin: stackoverflow.com
FileOutputStream out = new FileOutputStream(filename);
[...]
out.flush();
out.getFD().sync();
代码示例来源:origin: wildfly/wildfly
void setFile(final File file) throws IOException {
boolean ok = false;
final FileOutputStream fos = new FileOutputStream(file, true);
try {
final OutputStream bos = new BufferedOutputStream(fos);
try {
this.fileDescriptor = fos.getFD();
this.outputStream = bos;
this.file = file;
ok = true;
} finally {
if (! ok) {
safeClose(bos);
}
}
} finally {
if (! ok) {
safeClose(fos);
}
}
}
代码示例来源:origin: android-hacker/VirtualXposed
/**
* @deprecated This is not safe.
*/
public void truncate() throws IOException {
try {
FileOutputStream fos = new FileOutputStream(mBaseName);
fos.getFD().sync();
fos.close();
} catch (FileNotFoundException e) {
throw new IOException("Couldn't append " + mBaseName);
} catch (IOException e) {
}
}
代码示例来源:origin: robolectric/robolectric
FileOutputStream stream = new FileOutputStream(path);
FileDescriptor fd = stream.getFD();
fdToStream.put(fd, stream);
代码示例来源:origin: android-hacker/VirtualXposed
static boolean sync(FileOutputStream stream) {
try {
if (stream != null) {
stream.getFD().sync();
}
return true;
} catch (IOException e) {
}
return false;
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void run() {
// Do not write the file if committedOffset has never been updated.
if (committedOffset.get() == DEFAULT_COMMITTED_OFFSET) {
return;
}
try (final FileOutputStream fos = new FileOutputStream(committedReadOffsetFile)) {
fos.write(String.valueOf(committedOffset.get()).getBytes(StandardCharsets.UTF_8));
// flush stream
fos.flush();
// actually sync to disk
fos.getFD().sync();
} catch (SyncFailedException e) {
LOG.error("Cannot sync " + committedReadOffsetFile.getAbsolutePath() + " to disk. Continuing anyway," +
" but there is no guarantee that the file has been written.", e);
} catch (IOException e) {
LOG.error("Cannot write " + committedReadOffsetFile.getAbsolutePath() + " to disk.", e);
}
}
}
代码示例来源:origin: stackoverflow.com
private FileDescriptor openFile(String path)
throws FileNotFoundException, IOException {
File file = new File(path);
FileOutputStream fos = new FileOutputStream(file);
// remember th 'fos' reference somewhere for later closing it
fos.write((new Date() + " Beginning of process...").getBytes());
return fos.getFD();
}
代码示例来源:origin: apache/nifi
@Override
protected synchronized void syncUnderlyingOutputStream() throws IOException {
if (fos != null) {
fos.getFD().sync();
}
}
代码示例来源:origin: greenrobot/essentials
/** To store an object in a quick & dirty way. */
public static void writeObject(File file, Object object) throws IOException {
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fileOut));
try {
out.writeObject(object);
out.flush();
// Force sync
fileOut.getFD().sync();
} finally {
IoUtils.safeClose(out);
}
}
代码示例来源:origin: org.w3c.jigsaw/jigsaw
public static void main (String args[])
throws FileNotFoundException, IOException
{
Shuffler s = new Shuffler(args[0]) ;
FileInputStream f = new FileInputStream ("from") ;
FileOutputStream t = new FileOutputStream ("to") ;
s.shuffle (f.getFD(), t.getFD()) ;
f.close() ;
t.close() ;
}
}
代码示例来源:origin: apache/nifi
@Override
public void sync() throws IOException {
fos.getFD().sync();
}
代码示例来源:origin: greenrobot/essentials
/** To store an object in a quick & dirty way. */
public static void writeObject(File file, Object object) throws IOException {
FileOutputStream fileOut = new FileOutputStream(file);
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fileOut));
try {
out.writeObject(object);
out.flush();
// Force sync
fileOut.getFD().sync();
} finally {
IoUtils.safeClose(out);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common-test
@Test
public void testFstatClosedFd() throws Exception {
FileOutputStream fos = new FileOutputStream(
new File(TEST_DIR, "testfstat2"));
fos.close();
try {
NativeIO.Stat stat = NativeIO.fstat(fos.getFD());
} catch (NativeIOException nioe) {
LOG.info("Got expected exception", nioe);
assertEquals(Errno.EBADF, nioe.getErrno());
}
}
代码示例来源:origin: apache/nifi
@Override
public void close() throws IOException {
if (alwaysSync) {
fos.getFD().sync();
}
fos.close();
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void run() {
try {
fileToEdit.getParentFile().mkdirs();
FileOutputStream fos=new FileOutputStream(fileToEdit);
Writer w=new BufferedWriter(new OutputStreamWriter(fos));
try {
w.write(text);
w.flush();
fos.getFD().sync();
}
finally {
w.close();
}
}
catch (IOException e) {
Log.e(getClass().getSimpleName(), "Exception writing file", e);
}
}
}
代码示例来源:origin: com.spotify.sparkey/sparkey
private static BlockOutput setup(LogHeader header, File file) throws IOException {
truncate(file, header.getDataEnd());
FileOutputStream fileOutputStream = new FileOutputStream(file, true);
FileDescriptor fd = fileOutputStream.getFD();
OutputStream stream = new BufferedOutputStream(fileOutputStream, 1024 * 1024);
return header.getCompressionType().createBlockOutput(fd, stream, header.getCompressionBlockSize(),
header.getMaxEntriesPerBlock());
}
代码示例来源:origin: apache/nifi
@Override
public void close() throws IOException {
flush();
out.getFD().sync();
out.close();
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void run() {
try {
fileToEdit.getParentFile().mkdirs();
FileOutputStream fos=new FileOutputStream(fileToEdit);
Writer w=new BufferedWriter(new OutputStreamWriter(fos));
try {
w.write(text);
w.flush();
fos.getFD().sync();
}
finally {
w.close();
}
}
catch (IOException e) {
Log.e(getClass().getSimpleName(), "Exception writing file", e);
}
}
}
代码示例来源:origin: spotify/sparkey-java
private static BlockOutput setup(LogHeader header, File file) throws IOException {
truncate(file, header.getDataEnd());
FileOutputStream fileOutputStream = new FileOutputStream(file, true);
FileDescriptor fd = fileOutputStream.getFD();
OutputStream stream = new BufferedOutputStream(fileOutputStream, 1024 * 1024);
return header.getCompressionType().createBlockOutput(fd, stream, header.getCompressionBlockSize(),
header.getMaxEntriesPerBlock());
}
内容来源于网络,如有侵权,请联系作者删除!