org.jboss.netty.handler.codec.http2
Class AbstractDiskHttpData

java.lang.Object
  extended by org.jboss.netty.handler.codec.http2.AbstractHttpData
      extended by org.jboss.netty.handler.codec.http2.AbstractDiskHttpData
All Implemented Interfaces:
Comparable<InterfaceHttpData>, HttpData, InterfaceHttpData
Direct Known Subclasses:
DiskAttribute, DiskFileUpload

public abstract class AbstractDiskHttpData
extends AbstractHttpData
implements HttpData

Abstract Disk HttpData implementation

Author:
The Netty Project, Andy Taylor (andy.taylor@jboss.org), Trustin Lee, Frederic Bregier

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.netty.handler.codec.http2.InterfaceHttpData
InterfaceHttpData.HttpDataType
 
Field Summary
protected  File file
           
 
Fields inherited from class org.jboss.netty.handler.codec.http2.AbstractHttpData
charset, completed, definedSize, name, size
 
Constructor Summary
AbstractDiskHttpData(String name, Charset charset, long size)
           
 
Method Summary
 void addContent(org.jboss.netty.buffer.ChannelBuffer buffer, boolean last)
          Add the content from the ChannelBuffer
 void delete()
          Deletes the underlying storage for a file item, including deleting any associated temporary disk file.
protected abstract  boolean deleteOnExit()
           
 byte[] get()
          Returns the contents of the file item as an array of bytes.
protected abstract  String getBaseDirectory()
           
 org.jboss.netty.buffer.ChannelBuffer getChannelBuffer()
          Returns the content of the file item as a ChannelBuffer
 org.jboss.netty.buffer.ChannelBuffer getChunk(int length)
          Returns a ChannelBuffer for the content from the current position with at most length read bytes, increasing the current position of the Bytes read.
protected abstract  String getDiskFilename()
           
 File getFile()
           
protected abstract  String getPostfix()
           
protected abstract  String getPrefix()
           
 String getString()
          Returns the contents of the file item as a String, using the default character encoding.
 String getString(Charset encoding)
          Returns the contents of the file item as a String, using the specified charset.
 boolean isInMemory()
          Provides a hint as to whether or not the file contents will be read from memory.
 boolean renameTo(File dest)
          A convenience method to write an uploaded item to disk.
 void setContent(org.jboss.netty.buffer.ChannelBuffer buffer)
          Set the content from the ChannelBuffer (erase any previous data)
 void setContent(File file)
          Set the content from the file (erase any previous data)
 void setContent(InputStream inputStream)
          Set the content from the inputStream (erase any previous data)
 
Methods inherited from class org.jboss.netty.handler.codec.http2.AbstractHttpData
getCharset, getName, isCompleted, length, setCharset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.netty.handler.codec.http2.HttpData
getCharset, isCompleted, length, setCharset
 
Methods inherited from interface org.jboss.netty.handler.codec.http2.InterfaceHttpData
getHttpDataType, getName
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

file

protected File file
Constructor Detail

AbstractDiskHttpData

public AbstractDiskHttpData(String name,
                            Charset charset,
                            long size)
                     throws NullPointerException,
                            IllegalArgumentException
Throws:
NullPointerException
IllegalArgumentException
Method Detail

getDiskFilename

protected abstract String getDiskFilename()
Returns:
the real DiskFilename (basename)

getPrefix

protected abstract String getPrefix()
Returns:
the default prefix

getBaseDirectory

protected abstract String getBaseDirectory()
Returns:
the default base Directory

getPostfix

protected abstract String getPostfix()
Returns:
the default postfix

deleteOnExit

protected abstract boolean deleteOnExit()
Returns:
True if the file should be deleted on Exit by default

setContent

public void setContent(org.jboss.netty.buffer.ChannelBuffer buffer)
                throws IOException
Description copied from interface: HttpData
Set the content from the ChannelBuffer (erase any previous data)

Specified by:
setContent in interface HttpData
Parameters:
buffer - must be not null
Throws:
IOException

addContent

public void addContent(org.jboss.netty.buffer.ChannelBuffer buffer,
                       boolean last)
                throws IOException
Description copied from interface: HttpData
Add the content from the ChannelBuffer

Specified by:
addContent in interface HttpData
Parameters:
buffer - must be not null except if last is set to False
last - True of the buffer is the last one
Throws:
IOException

setContent

public void setContent(File file)
                throws IOException
Description copied from interface: HttpData
Set the content from the file (erase any previous data)

Specified by:
setContent in interface HttpData
Parameters:
file - must be not null
Throws:
IOException

setContent

public void setContent(InputStream inputStream)
                throws IOException
Description copied from interface: HttpData
Set the content from the inputStream (erase any previous data)

Specified by:
setContent in interface HttpData
Parameters:
inputStream - must be not null
Throws:
IOException

delete

public void delete()
Description copied from interface: HttpData
Deletes the underlying storage for a file item, including deleting any associated temporary disk file.

Specified by:
delete in interface HttpData

get

public byte[] get()
           throws IOException
Description copied from interface: HttpData
Returns the contents of the file item as an array of bytes.

Specified by:
get in interface HttpData
Returns:
the contents of the file item as an array of bytes.
Throws:
IOException

getChannelBuffer

public org.jboss.netty.buffer.ChannelBuffer getChannelBuffer()
                                                      throws IOException
Description copied from interface: HttpData
Returns the content of the file item as a ChannelBuffer

Specified by:
getChannelBuffer in interface HttpData
Returns:
the content of the file item as a ChannelBuffer
Throws:
IOException

getChunk

public org.jboss.netty.buffer.ChannelBuffer getChunk(int length)
                                              throws IOException
Description copied from interface: HttpData
Returns a ChannelBuffer for the content from the current position with at most length read bytes, increasing the current position of the Bytes read. Once it arrives at the end, it returns an EMPTY_BUFFER and it resets the current position to 0.

Specified by:
getChunk in interface HttpData
Returns:
a ChannelBuffer for the content from the current position or an EMPTY_BUFFER if there is no more data to return
Throws:
IOException

getString

public String getString()
                 throws IOException
Description copied from interface: HttpData
Returns the contents of the file item as a String, using the default character encoding.

Specified by:
getString in interface HttpData
Returns:
the contents of the file item as a String, using the default character encoding.
Throws:
IOException

getString

public String getString(Charset encoding)
                 throws IOException
Description copied from interface: HttpData
Returns the contents of the file item as a String, using the specified charset.

Specified by:
getString in interface HttpData
Parameters:
encoding - the charset to use
Returns:
the contents of the file item as a String, using the specified charset.
Throws:
IOException

isInMemory

public boolean isInMemory()
Description copied from interface: HttpData
Provides a hint as to whether or not the file contents will be read from memory.

Specified by:
isInMemory in interface HttpData
Returns:
True if the file contents is in memory.

renameTo

public boolean renameTo(File dest)
                 throws IOException
Description copied from interface: HttpData
A convenience method to write an uploaded item to disk. If a previous one exists, it will be deleted. Once this method is called, if successful, the new file will be out of the cleaner of the factory that creates the original InterfaceHttpData object.

Specified by:
renameTo in interface HttpData
Parameters:
dest - destination file - must be not null
Returns:
True if the write is successful
Throws:
IOException

getFile

public File getFile()
             throws IOException
Specified by:
getFile in interface HttpData
Returns:
the associated File if this data is represented in a file
Throws:
IOException - if this data is not represented by a file


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.