Class AssetFileOutputStream

java.lang.Object
java.io.OutputStream
com.tianscar.assetfile.AssetFileOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class AssetFileOutputStream extends OutputStream
An OutputStream that packaging an AssetFileDescriptor#AutoCloseOutputStream for use.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AssetFileOutputStream​(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.
    Creates a AssetFileOutputStream by opening a connection to an actual file in assets, the file named by the AssetFile file.
    Creates a AssetFileOutputStream by opening a connection to an actual file in assets, the file named by the name string.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this asset file output stream and releases any system resources associated with this stream.
    boolean
    equals​(Object o)
     
    void
    Flushes this asset output stream and forces any buffered output bytes to be written out.
    android.content.res.AssetFileDescriptor
    Returns the asset file descriptor associated with this stream.
    Returns the unique FileChannel object associated with this asset file output stream.
    Returns the file descriptor associated with this stream.
    int
     
    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.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AssetFileOutputStream

      public AssetFileOutputStream(@NonNull String name) throws IOException
      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

      public AssetFileOutputStream(@NonNull AssetFile file) throws IOException
      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 IOException
      Creates 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

      public void close() throws IOException
      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 interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(int b) throws IOException
      Writes the specified byte to this file output stream. Implements the write method of OutputStream.
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte to be written.
      Throws:
      IOException - If an I/O error occurred
    • write

      public void write(byte[] b) throws IOException
      Writes b.length bytes from the specified byte array to this file output stream.
      Overrides:
      write in class OutputStream
      Parameters:
      b - the data.
      Throws:
      IOException - If an I/O error occurred
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Writes len bytes from the specified byte array starting at offset off to this file output stream.
      Overrides:
      write in class OutputStream
      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

      public void flush() throws IOException
      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 interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - if an I/O error occurs.
    • getChannel

      public FileChannel 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

      public final FileDescriptor getFD() throws IOException
      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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object