org.jmythapi.protocol.response.impl
Class FileTransfer

java.lang.Object
  extended by org.jmythapi.impl.AData<E>
      extended by org.jmythapi.protocol.response.impl.AMythResponse<IFileTransfer.Props>
          extended by org.jmythapi.protocol.response.impl.FileTransfer
All Implemented Interfaces:
Closeable, Cloneable, IPropertyAware<IFileTransfer.Props>, IVersionable, ISendable, IFileTransfer, IMythResponse<IFileTransfer.Props>, ITransferable<IFileTransfer.Props>

public class FileTransfer
extends AMythResponse<IFileTransfer.Props>
implements Closeable, IFileTransfer

Since:
00

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jmythapi.protocol.response.IFileTransfer
IFileTransfer.Props
 
Nested classes/interfaces inherited from interface org.jmythapi.protocol.response.ITransferable
ITransferable.Seek
 
Field Summary
static int DEFAULT_BUFFER_SIZE
           
 
Fields inherited from class org.jmythapi.impl.AData
logger, propsClass, protoVersion, respArgs
 
Constructor Summary
FileTransfer(IBackendConnection commandConnection, IBackendConnection dataConnection, IMythPacket packet)
           
 
Method Summary
 Object clone()
          Creates a copy of this object.
 void close()
           
 boolean done()
          Closes the file transfer connection.
 long getFileSize()
          Gets the current file size.
 InputStream getInputStream()
          Gets an input stream to read the file data.
 InputStream getInputStream(int bufferSize)
          Gets an input stream to read the file data.
 int getSocketID()
          Gets the file transfer socket id.
 String getStatus()
          Gets the file transfer status.
 boolean isOpen()
          Queries whether a file socket is currently open.
 int readBlock(byte[] buffer, int requestedSize)
          This method sends a block request to the backend, but does not wait for the response.
 int readData(byte[] buffer, int reportedLength)
          Reads the given amount of data from the backend.
 boolean reopen(String fileName)
          Reopens the remote file.
 int requestBlock(int requestedLength)
          Requests data from the backend.
 long seek(long currentPos, long newPos, ITransferable.Seek whence)
          This command wraps the file "seek" function.
 void setFileInfo(String fileName, String storageGroup)
           
 void setProgramInfo(IProgramInfo programInfo)
           
 boolean setTimeout(boolean fast)
          Sets the timout mode.
 void transferTo(File target)
          Copies the remote file into the local file.
 void transferTo(OutputStream fileOut)
          Copies the remote file into the given output stream.
 boolean updateFileSize()
          Updates the file information of the file-transfer object.
 
Methods inherited from class org.jmythapi.protocol.response.impl.AMythResponse
checkSize, decodeProperty, encodeProperty, getExpectedSize, getPacket, getProperties, getProperty, getPropertyIndex
 
Methods inherited from class org.jmythapi.impl.AData
equals, getPropertyClass, getPropertyCount, getPropertyMap, getPropertyValue, getPropertyValue, getPropertyValueObject, getPropertyValueObject, getPropertyValues, getVersionNr, hashCode, init, postProcessArguments, setPropertyValue, setPropertyValue, setPropertyValueObject, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jmythapi.IVersionable
getVersionNr
 
Methods inherited from interface org.jmythapi.IPropertyAware
getProperties, getProperty, getPropertyClass, getPropertyCount, getPropertyIndex, getPropertyMap, getPropertyValue, getPropertyValue, getPropertyValueObject, getPropertyValues, setPropertyValue, setPropertyValue, setPropertyValueObject
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

FileTransfer

public FileTransfer(IBackendConnection commandConnection,
                    IBackendConnection dataConnection,
                    IMythPacket packet)
Method Detail

clone

public Object clone()
             throws CloneNotSupportedException
Description copied from class: AData
Creates a copy of this object.

Overrides:
clone in class AData<IFileTransfer.Props>
Returns:
a copy of this object
Throws:
CloneNotSupportedException

setProgramInfo

public void setProgramInfo(IProgramInfo programInfo)

setFileInfo

public void setFileInfo(String fileName,
                        String storageGroup)

getStatus

public String getStatus()
Description copied from interface: IFileTransfer
Gets the file transfer status.

Specified by:
getStatus in interface IFileTransfer
Returns:
OK or ERROR

getSocketID

public int getSocketID()
Description copied from interface: IFileTransfer
Gets the file transfer socket id.

Specified by:
getSocketID in interface IFileTransfer
Returns:
the socket id

getFileSize

public long getFileSize()
Description copied from interface: IFileTransfer
Gets the current file size.

For a in progress recording this file size may increase.
Use IFileTransfer.updateFileSize() to update the file size.

Specified by:
getFileSize in interface IFileTransfer
Returns:
the current file size

updateFileSize

public boolean updateFileSize()
                       throws IOException
Description copied from interface: IFileTransfer
Updates the file information of the file-transfer object.

If the transfer object was initiated from an IProgramInfo object (see IBackend.annotateFileTransfer(IProgramInfo)), then this function uses IMythCommand.FILL_PROGRAM_INFO to determine the new file size.

If the transfer object was initialized using a file name, and the current protocol version is greater or equal 44, then IMythCommand.QUERY_SG_FILEQUERY is used to determine the new file size. But this method may fail if the requested file is not stored in a file group, e.g. a channel icon.

Specified by:
updateFileSize in interface IFileTransfer
Returns:
true on success.
Throws:
IOException - on communication errors

readBlock

public int readBlock(byte[] buffer,
                     int requestedSize)
              throws IOException
This method sends a block request to the backend, but does not wait for the response. We do because of the following reason:

See DSMyth - RemoteFile.cpp:


The response from REQUEST_BLOCK is not sent until all of the requested data is sent. That means that we have to read from the data socket while waiting for the reply on the control socket. If we don't read data from the data socket the backend will timeout with an error. This means that the network must be fast enough so we can get the data before the backend times out.

Specified by:
readBlock in interface IFileTransfer
Specified by:
readBlock in interface ITransferable<IFileTransfer.Props>
Parameters:
buffer - the byte buffer to fill with data
requestedSize - the amount of bytes to read
Returns:
the read byte count
Throws:
IOException - on communication errors

requestBlock

public int requestBlock(int requestedLength)
                 throws IOException
Description copied from interface: IFileTransfer
Requests data from the backend.

Specified by:
requestBlock in interface IFileTransfer
Parameters:
requestedLength - the amount of bytes to request.
Returns:
the amount of returned bytes. this may be less than the requested size.
Throws:
IOException - on communication errors

readData

public int readData(byte[] buffer,
                    int reportedLength)
             throws IOException
Description copied from interface: IFileTransfer
Reads the given amount of data from the backend.

Specified by:
readData in interface IFileTransfer
Parameters:
buffer - the buffer to fill with data
reportedLength - the amount of data to read
Returns:
the actually amount of read data
Throws:
IOException - on communication errors

seek

public long seek(long currentPos,
                 long newPos,
                 ITransferable.Seek whence)
          throws IOException
Description copied from interface: IFileTransfer

This command wraps the file "seek" function.

The pos and curpos fields are combined into a larger "long long" data type. This returns two values, a split "long long" value for the result.

Specified by:
seek in interface IFileTransfer
Specified by:
seek in interface ITransferable<IFileTransfer.Props>
Parameters:
currentPos - the current position
newPos - the new position
whence - the seek mode
Returns:
the new position
Throws:
IOException - on communication errors
See Also:
QUERY_FILETRANSFER_SEEK

isOpen

public boolean isOpen()
               throws IOException
Description copied from interface: IFileTransfer
Queries whether a file socket is currently open.

Specified by:
isOpen in interface IFileTransfer
Specified by:
isOpen in interface ITransferable<IFileTransfer.Props>
Returns:
true if the socket is open.
Throws:
IOException - on communication errors

setTimeout

public boolean setTimeout(boolean fast)
                   throws IOException
Description copied from interface: IFileTransfer
Sets the timout mode.

This command sets whether reading from a file should have a fast or slow timeout.
Slow timeouts are used for live TV ring buffers, and is three seconds. Fast timeouts are used for static files, and are 0.12 seconds.

Specified by:
setTimeout in interface IFileTransfer
Throws:
IOException
See Also:
QUERY_FILETRANSFER_SET_TIMEOUT

done

public boolean done()
             throws IOException
Description copied from interface: IFileTransfer
Closes the file transfer connection.

Specified by:
done in interface IFileTransfer
Specified by:
done in interface ITransferable<IFileTransfer.Props>
Returns:
true on success.
Throws:
IOException - on communication errors
See Also:
QUERY_FILETRANSFER_DONE

reopen

public boolean reopen(String fileName)
               throws IOException
Description copied from interface: IFileTransfer
Reopens the remote file.

Specified by:
reopen in interface IFileTransfer
Throws:
IOException
See Also:
QUERY_FILETRANSFER_REOPEN

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in interface ITransferable<IFileTransfer.Props>
Throws:
IOException

transferTo

public void transferTo(File target)
                throws IOException
Description copied from interface: IFileTransfer
Copies the remote file into the local file.

This function transfers the full remote file into the specified target file.

Specified by:
transferTo in interface IFileTransfer
Parameters:
target - the file to write data to.
Throws:
IOException - on communication errors

transferTo

public void transferTo(OutputStream fileOut)
                throws IOException
Description copied from interface: IFileTransfer
Copies the remote file into the given output stream.

This function transfers the full remote file into the specified target stream.

Specified by:
transferTo in interface IFileTransfer
Parameters:
fileOut - the output stream
Throws:
IOException - on communication errors

getInputStream

public InputStream getInputStream()
                           throws IOException
Description copied from interface: IFileTransfer
Gets an input stream to read the file data.

This function creates an input-stream that can be used to read the data of this file-transfer object.

Specified by:
getInputStream in interface IFileTransfer
Returns:
an input stream to read the file
Throws:
IOException - on communication errors

getInputStream

public InputStream getInputStream(int bufferSize)
                           throws IOException
Description copied from interface: IFileTransfer
Gets an input stream to read the file data.

This function creates an input-stream that can be used to read the data of this file-transfer object.
* The maximum size of the data chunks that should be fetched by the stream can be spezified.

Specified by:
getInputStream in interface IFileTransfer
Parameters:
bufferSize - the maximum size of the data chunks to fetch
Returns:
an input stream to read data
Throws:
IOException - on communication errors


Copyright © 2008-2013. All Rights Reserved.