Top Description Fields Constructors Methods
org.apache.poi.poifs.nio

public Class FileBackedDataSource

extends DataSource
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .File, .FileNotFoundException, .IOException, .OutputStream, .RandomAccessFile, java.nio.ByteBuffer, java.nio.channels.Channels, .FileChannel, .WritableByteChannel, java.util.IdentityHashMap, org.apache.logging.log4j.LogManager, .Logger, org.apache.poi.util.IOUtils

A POIFS DataSource backed by a File

Field Summary

Modifier and TypeField and Description
private final IdentityHashMap<ByteBuffer, ByteBuffer>
private final FileChannel
private Long
private final boolean
private static final Logger
private final RandomAccessFile
private final boolean

Constructor Summary

AccessConstructor and Description
public
public
FileBackedDataSource(File file, boolean readOnly)

public
FileBackedDataSource(RandomAccessFile srcFile, boolean readOnly)

public
FileBackedDataSource(FileChannel channel, boolean readOnly)

public
FileBackedDataSource(FileChannel channel, boolean readOnly, boolean closeChannelOnClose)

private
FileBackedDataSource(RandomAccessFile srcFile, FileChannel channel, boolean readOnly, boolean closeChannelOnClose)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract org.apache.poi.poifs.nio.DataSource.close.

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public void
copyTo(OutputStream stream)

Implements abstract org.apache.poi.poifs.nio.DataSource.copyTo.

Copies the contents to the specified OutputStream

public FileChannel
public boolean
private static RandomAccessFile
newSrcFile(File file, String mode)

public ByteBuffer
read(int length, long position)

Implements abstract org.apache.poi.poifs.nio.DataSource.read.

public void
public long
private static void
unmap(final ByteBuffer buffer)

public void
write(ByteBuffer src, long position)

Implements abstract org.apache.poi.poifs.nio.DataSource.write.

Field Detail

buffersToCleanback to summary
private final IdentityHashMap<ByteBuffer, ByteBuffer> buffersToClean
channelback to summary
private final FileChannel channel
channelSizeback to summary
private Long channelSize
closeChannelOnCloseback to summary
private final boolean closeChannelOnClose
LOGback to summary
private static final Logger LOG
srcFileback to summary
private final RandomAccessFile srcFile
writableback to summary
private final boolean writable

Constructor Detail

FileBackedDataSourceback to summary
public FileBackedDataSource(File file) throws FileNotFoundException
FileBackedDataSourceback to summary
public FileBackedDataSource(File file, boolean readOnly) throws FileNotFoundException
FileBackedDataSourceback to summary
public FileBackedDataSource(RandomAccessFile srcFile, boolean readOnly)
FileBackedDataSourceback to summary
public FileBackedDataSource(FileChannel channel, boolean readOnly)
FileBackedDataSourceback to summary
public FileBackedDataSource(FileChannel channel, boolean readOnly, boolean closeChannelOnClose)
Since
POI 5.1.0
FileBackedDataSourceback to summary
private FileBackedDataSource(RandomAccessFile srcFile, FileChannel channel, boolean readOnly, boolean closeChannelOnClose)

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract org.apache.poi.poifs.nio.DataSource.close.

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
copyToback to summary
public void copyTo(OutputStream stream) throws IOException

Implements abstract org.apache.poi.poifs.nio.DataSource.copyTo.

Doc from org.apache.poi.poifs.nio.DataSource.copyTo.

Copies the contents to the specified OutputStream

Annotations
@Override
getChannelback to summary
public FileChannel getChannel()
isWriteableback to summary
public boolean isWriteable()
newSrcFileback to summary
private static RandomAccessFile newSrcFile(File file, String mode) throws FileNotFoundException
readback to summary
public ByteBuffer read(int length, long position) throws IOException

Implements abstract org.apache.poi.poifs.nio.DataSource.read.

Annotations
@Override
releaseBufferback to summary
public void releaseBuffer(ByteBuffer buffer)
sizeback to summary
public long size() throws IOException

Implements abstract org.apache.poi.poifs.nio.DataSource.size.

Annotations
@Override
unmapback to summary
private static void unmap(final ByteBuffer buffer)
writeback to summary
public void write(ByteBuffer src, long position) throws IOException

Implements abstract org.apache.poi.poifs.nio.DataSource.write.

Annotations
@Override