Class TFileTransport

java.lang.Object
org.apache.thrift.transport.TTransport
org.apache.thrift.transport.TFileTransport
All Implemented Interfaces:
Closeable, AutoCloseable

public class TFileTransport extends TTransport
FileTransport implementation of the TTransport interface. Currently this is a straightforward port of the cpp implementation

It may make better sense to provide a basic stream access on top of the framed file format The FileTransport can then be a user of this framed file format with some additional logic for chunking.

  • Field Details

    • inputFile_

      protected TSeekableFile inputFile_
      Underlying file being read
    • outputStream_

      protected OutputStream outputStream_
      Underlying outputStream
  • Constructor Details

    • TFileTransport

      public TFileTransport(String path, boolean readOnly) throws IOException
      File Transport ctor
      Parameters:
      path - File path to read and write from
      readOnly - Whether this is a read-only transport
      Throws:
      IOException - if there is an error accessing the file.
    • TFileTransport

      public TFileTransport(TSeekableFile inputFile, boolean readOnly)
      File Transport ctor
      Parameters:
      inputFile - open TSeekableFile to read/write from
      readOnly - Whether this is a read-only transport
  • Method Details

    • getTailPolicy

      public TFileTransport.TailPolicy getTailPolicy()
      Get File Tailing Policy
      Returns:
      current read policy
    • setTailPolicy

      Set file Tailing Policy
      Parameters:
      policy - New policy to set
      Returns:
      Old policy
    • isOpen

      public boolean isOpen()
      open if both input/output open unless readonly
      Specified by:
      isOpen in class TTransport
      Returns:
      true
    • open

      public void open() throws TTransportException
      Diverging from the cpp model and sticking to the TSocket model Files are not opened in ctor - but in explicit open call
      Specified by:
      open in class TTransport
      Throws:
      TTransportException - if the transport could not be opened
    • close

      public void close()
      Closes the transport.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class TTransport
    • readAll

      public int readAll(byte[] buf, int off, int len) throws TTransportException
      Cloned from TTransport.java:readAll(). Only difference is throwing an EOF exception where one is detected.
      Overrides:
      readAll in class TTransport
      Parameters:
      buf - Array to read into
      off - Index to start reading at
      len - Maximum number of bytes to read
      Returns:
      The number of bytes actually read, which must be equal to len
      Throws:
      TTransportException - if there was an error reading data
    • read

      public int read(byte[] buf, int off, int len) throws TTransportException
      Reads up to len bytes into buffer buf, starting at offset off.
      Specified by:
      read in class TTransport
      Parameters:
      buf - Array to read into
      off - Index to start reading at
      len - Maximum number of bytes to read
      Returns:
      The number of bytes actually read
      Throws:
      TTransportException - if there was an error reading data
    • getNumChunks

      public int getNumChunks() throws TTransportException
      Throws:
      TTransportException
    • getCurChunk

      public int getCurChunk() throws TTransportException
      Throws:
      TTransportException
    • seekToChunk

      public void seekToChunk(int chunk) throws TTransportException
      Throws:
      TTransportException
    • seekToEnd

      public void seekToEnd() throws TTransportException
      Throws:
      TTransportException
    • write

      public void write(byte[] buf, int off, int len) throws TTransportException
      Writes up to len bytes from the buffer.
      Specified by:
      write in class TTransport
      Parameters:
      buf - The output data buffer
      off - The offset to start writing from
      len - The number of bytes to write
      Throws:
      TTransportException - if there was an error writing data
    • flush

      public void flush() throws TTransportException
      Flush any pending data out of a transport buffer.
      Overrides:
      flush in class TTransport
      Throws:
      TTransportException - if there was an error writing out data.
    • getConfiguration

      public TConfiguration getConfiguration()
      Specified by:
      getConfiguration in class TTransport
    • updateKnownMessageSize

      public void updateKnownMessageSize(long size) throws TTransportException
      Specified by:
      updateKnownMessageSize in class TTransport
      Throws:
      TTransportException
    • checkReadBytesAvailable

      public void checkReadBytesAvailable(long numBytes) throws TTransportException
      Specified by:
      checkReadBytesAvailable in class TTransport
      Throws:
      TTransportException
    • resetMessageSizeAndConsumedBytes

      public void resetMessageSizeAndConsumedBytes(long newSize) throws TTransportException
      Description copied from class: TTransport
      Sets the read budget to newSize, discarding whatever has been consumed against the previous one. A negative size restores the configured maximum.

      This is the only way to widen a budget that an earlier, smaller message narrowed: updateKnownMessageSize() refuses to grow one, and carries the previous message's consumption forward besides. A caller that learns the real size of a message -- a framed transport reading a frame header, say -- wants this rather than updateKnownMessageSize(), because the reads that told it the size were themselves charged against the budget it is about to replace.

      Specified by:
      resetMessageSizeAndConsumedBytes in class TTransport
      Parameters:
      newSize - the size to bind the budget to, or a negative value for the configured maximum
      Throws:
      TTransportException
    • main

      public static void main(String[] args) throws Exception
      test program
      Throws:
      Exception