Package com.tianscar.assetfile
Class AssetFileOutputStream
java.lang.Object
java.io.OutputStream
com.tianscar.assetfile.AssetFileOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
An OutputStream that packaging an AssetFileDescriptor#AutoCloseOutputStream for use.
-
Constructor Summary
ConstructorDescriptionAssetFileOutputStream(android.content.res.AssetFileDescriptor fdObj)
Creates a FileOutputStream by using the asset file descriptor fdObj, which represents an existing connection to an actual file in assets.AssetFileOutputStream(AssetFile file)
Creates a AssetFileOutputStream by opening a connection to an actual file in assets, the file named by the AssetFile file.AssetFileOutputStream(String name)
Creates a AssetFileOutputStream by opening a connection to an actual file in assets, the file named by the name string. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this asset file output stream and releases any system resources associated with this stream.boolean
void
flush()
Flushes this asset output stream and forces any buffered output bytes to be written out.android.content.res.AssetFileDescriptor
getAFD()
Returns the asset file descriptor associated with this stream.Returns the unique FileChannel object associated with this asset file output stream.getFD()
Returns the file descriptor associated with this stream.int
hashCode()
void
write(byte[] b)
Writes b.length bytes from the specified byte array to this file output stream.void
write(byte[] b, int off, int len)
Writes len bytes from the specified byte array starting at offset off to this file output stream.void
write(int b)
Writes the specified byte to this file output stream.
-
Constructor Details
-
AssetFileOutputStream
Creates a AssetFileOutputStream by opening a connection to an actual file in assets, the file named by the name string. A new AssetFileDescriptor object is created to represent this file connection.- Parameters:
name
- the assetFile name.- Throws:
IOException
- If an I/O error occurred
-
AssetFileOutputStream
Creates a AssetFileOutputStream by opening a connection to an actual file in assets, the file named by the AssetFile file. A new AssetFileDescriptor object is created to represent this file connection.- Parameters:
file
- the assetFile to be opened for reading.- Throws:
IOException
- If an I/O error occurred
-
AssetFileOutputStream
public AssetFileOutputStream(@NonNull android.content.res.AssetFileDescriptor fdObj) throws IOExceptionCreates a FileOutputStream by using the asset file descriptor fdObj, which represents an existing connection to an actual file in assets.- Parameters:
fdObj
- the asset file descriptor to be opened for reading.- Throws:
IOException
- If an I/O error occurred
-
-
Method Details
-
close
Closes this asset file output stream and releases any system resources associated with this stream. This asset file output stream may no longer be used for writing bytes. If this stream has an associated channel then the channel is closed as well.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
- if an I/O error occurs.
-
write
Writes the specified byte to this file output stream. Implements the write method of OutputStream.- Specified by:
write
in classOutputStream
- Parameters:
b
- the byte to be written.- Throws:
IOException
- If an I/O error occurred
-
write
Writes b.length bytes from the specified byte array to this file output stream.- Overrides:
write
in classOutputStream
- Parameters:
b
- the data.- Throws:
IOException
- If an I/O error occurred
-
write
Writes len bytes from the specified byte array starting at offset off to this file output stream.- Overrides:
write
in classOutputStream
- Parameters:
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.- Throws:
IOException
- If an I/O error occurred
-
flush
Flushes this asset output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination. If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive. The flush method of OutputStream does nothing.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- if an I/O error occurs.
-
getChannel
Returns the unique FileChannel object associated with this asset file output stream. The initial position of the returned channel will be equal to the number of bytes written to the file so far unless this stream is in append mode, in which case it will be equal to the size of the file. Writing bytes to this stream will increment the channel's position accordingly. Changing the channel's position, either explicitly or by writing, will change this stream's file position.- Returns:
- the file channel associated with this asset file output stream
-
getFD
Returns the file descriptor associated with this stream.- Returns:
- the FileDescriptor object that represents the connection to the file in assets being used by this AssetFileOutputStream object.
- Throws:
IOException
- if an I/O error occurs.
-
getAFD
public final android.content.res.AssetFileDescriptor getAFD()Returns the asset file descriptor associated with this stream.- Returns:
- the AssetFileDescriptor object that represents the connection to the file in assets being used by this AssetFileOutputStream object.
-
equals
-
hashCode
public int hashCode()
-