Top Description Fields Constructors Methods
io.netty.contrib.handler.codec.http.multipart

public abstract Class AbstractDiskHttpData

extends AbstractHttpData
Class Inheritance
Known Direct Subclasses
io.netty.contrib.handler.codec.http.multipart.DiskAttribute, io.netty.contrib.handler.codec.http.multipart.DiskFileUpload
Imports
io.netty5.buffer.Buffer, .DefaultBufferAllocators, io.netty5.channel.ChannelException, io.netty5.handler.codec.http.HttpConstants, io.netty5.util.internal.EmptyArrays, .ObjectUtil, .PlatformDependent, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, io.netty.contrib.handler.codec.http.multipart.Helpers.ThrowingConsumer, java.io.File, .IOException, .InputStream, .RandomAccessFile, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.nio.charset.Charset, java.nio.file.Files

Abstract Disk HttpData implementation

Field Summary

Modifier and TypeField and Description
private File
private FileChannel
private boolean
private static final InternalLogger
Inherited from io.netty.contrib.handler.codec.http.multipart.AbstractHttpData:
definedSizeEMPTY_ARRAYsize

Constructor Summary

AccessConstructor and Description
protected
AbstractDiskHttpData(String name, Charset charset, long size)

protected

Method Summary

Modifier and TypeMethod and Description
public void
addContent(Buffer
must be not null except if last is set to False
buffer
,
boolean
True of the buffer is the last one
last
)

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.addContent.

Add the content from the ChannelBuffer

Buffer#close() ownership of buffer is transferred to this HttpData.

public void
delete()

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.delete.

Deletes the underlying storage for a file item, including deleting any associated temporary disk file.
protected abstract boolean

Returns:

True if the file should be deleted on Exit by default
deleteOnExit
()

public byte[]
get()

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.get.

Returns the contents of the file item as an array of bytes.
protected abstract String

Returns:

the default base Directory
getBaseDirectory
()

private static Buffer
public Buffer
getChunk(int length)

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.getChunk.

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 Buffer
getContent()

Returns a copy of the current file content.

protected abstract String

Returns:

the real DiskFilename (basename)
getDiskFilename
()

public File
protected abstract String

Returns:

the default postfix
getPostfix
()

protected abstract String

Returns:

the default prefix
getPrefix
()

public String
getString()

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.getString.

Returns the contents of the file item as a String, using the default character encoding.
public String
getString(Charset
the charset to use
encoding
)

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.getString.

Returns the contents of the file item as a String, using the specified charset.
public boolean
isInMemory()

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.isInMemory.

Provides a hint as to whether or not the file contents will be read from memory.
private static byte[]

Returns:

the array of bytes
readFrom
(File src)

Utility function

public boolean
renameTo(File
destination file - must be not null
dest
)

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.renameTo.

A convenience getMethod to write an uploaded item to disk.
public void
setContent(Buffer
must be not null
buffer
)

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Set the content from the ChannelBuffer (erase any previous data)

Buffer#close() ownership of buffer is transferred to this HttpData.

public void
setContent(File
must be not null
file
)

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Set the content from the file (erase any previous data)
public void
setContent(InputStream
must be not null
inputStream
)

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Set the content from the inputStream (erase any previous data)
private File

Returns:

a new Temp File from getDiskFilename(), default prefix, postfix and baseDirectory
tempFile
()

public <E extends Exception> void
usingBuffer(Helpers.ThrowingConsumer<Buffer, E>
The file item buffer callback
callback
)

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.usingBuffer.

Calls the passed callback to operate on the file item as a Buffer.
Inherited from io.netty.contrib.handler.codec.http.multipart.AbstractHttpData:
checkAccessiblecheckAccessiblecheckSizecreateResourceClosedExceptiondefinedLengthgetCharsetgetMaxSizegetNameisCompletedlengthsetCharsetsetCompletedsetCompletedsetMaxSizeusingContent

Field Detail

fileback to summary
private File file
fileChannelback to summary
private FileChannel fileChannel
isRenamedback to summary
private boolean isRenamed
loggerback to summary
private static final InternalLogger logger

Constructor Detail

AbstractDiskHttpDataback to summary
protected AbstractDiskHttpData(String name, Charset charset, long size)
AbstractDiskHttpDataback to summary
protected AbstractDiskHttpData(AbstractDiskHttpData copy)

Method Detail

addContentback to summary
public void addContent(Buffer buffer, boolean last) throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.addContent.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.addContent.

Add the content from the ChannelBuffer

Buffer#close() ownership of buffer is transferred to this HttpData.

Parameters
buffer:Buffer

must be not null except if last is set to False

last:boolean

True of the buffer is the last one

Annotations
@Override
deleteback to summary
public void delete()

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.delete.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.delete.

Deletes the underlying storage for a file item, including deleting any associated temporary disk file.

Annotations
@Override
deleteOnExitback to summary
protected abstract boolean deleteOnExit()
Returns:boolean

True if the file should be deleted on Exit by default

getback to summary
public byte[] get() throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.get.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.get.

Returns the contents of the file item as an array of bytes.

Note

this method will allocate a lot of memory, if the data is currently stored on the file system.

Returns:byte[]

the contents of the file item as an array of bytes.

Annotations
@Override
getBaseDirectoryback to summary
protected abstract String getBaseDirectory()
Returns:String

the default base Directory

getBufferFromback to summary
private static Buffer getBufferFrom(File src) throws IOException
getChunkback to summary
public Buffer getChunk(int length) throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.getChunk.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.getChunk.

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.

Buffer ownersip: The buffer ownership of the returned buffer is transferred to the caller

Returns:Buffer

a ChannelBuffer for the content from the current position or an EMPTY_BUFFER if there is no more data to return

Annotations
@Override
getContentback to summary
protected Buffer getContent()

Returns a copy of the current file content. The buffer ownership is returned to the caller

getDiskFilenameback to summary
protected abstract String getDiskFilename()
Returns:String

the real DiskFilename (basename)

getFileback to summary
public File getFile() throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.getFile.

Returns:File

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.getFile.

the associated File if this data is represented in a file

Annotations
@Override
Exceptions
IOException:

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.getFile.

if this data is not represented by a file

getPostfixback to summary
protected abstract String getPostfix()
Returns:String

the default postfix

getPrefixback to summary
protected abstract String getPrefix()
Returns:String

the default prefix

getStringback to summary
public String getString() throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.getString.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.getString.

Returns the contents of the file item as a String, using the default character encoding.

Returns:String

the contents of the file item as a String, using the default character encoding.

Annotations
@Override
getStringback to summary
public String getString(Charset encoding) throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.getString.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.getString.

Returns the contents of the file item as a String, using the specified charset.

Parameters
encoding:Charset

the charset to use

Returns:String

the contents of the file item as a String, using the specified charset.

Annotations
@Override
isInMemoryback to summary
public boolean isInMemory()

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.isInMemory.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.isInMemory.

Provides a hint as to whether or not the file contents will be read from memory.

Returns:boolean

True if the file contents is in memory.

Annotations
@Override
readFromback to summary
private static byte[] readFrom(File src) throws IOException

Utility function

Returns:byte[]

the array of bytes

renameToback to summary
public boolean renameTo(File dest) throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.renameTo.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.renameTo.

A convenience getMethod to write an uploaded item to disk. If a previous one exists, it will be deleted. Once this getMethod is called, if successful, the new file will be out of the cleaner of the factory that creates the original InterfaceHttpData object.

Parameters
dest:File

destination file - must be not null

Returns:boolean

True if the write is successful

Annotations
@Override
setContentback to summary
public void setContent(Buffer buffer) throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Set the content from the ChannelBuffer (erase any previous data)

Buffer#close() ownership of buffer is transferred to this HttpData.

Parameters
buffer:Buffer

must be not null

Annotations
@Override
setContentback to summary
public void setContent(File file) throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Set the content from the file (erase any previous data)

Parameters
file:File

must be not null

Annotations
@Override
setContentback to summary
public void setContent(InputStream inputStream) throws IOException

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.setContent.

Set the content from the inputStream (erase any previous data)

Parameters
inputStream:InputStream

must be not null

Annotations
@Override
tempFileback to summary
private File tempFile() throws IOException
Returns:File

a new Temp File from getDiskFilename(), default prefix, postfix and baseDirectory

usingBufferback to summary
public <E extends Exception> void usingBuffer(Helpers.ThrowingConsumer<Buffer, E> callback) throws IOException, ThrowingConsumer-:E

Implements io.netty.contrib.handler.codec.http.multipart.HttpData.usingBuffer.

Doc from io.netty.contrib.handler.codec.http.multipart.HttpData.usingBuffer.

Calls the passed callback to operate on the file item as a Buffer.

Note

this method will allocate a lot of memory, if the data is currently stored on the file system.

Buffer ownersip:

The ownership of the buffer passed to the callack is not transferred and remains to this HttpData interface.
  • for memory based http data, the internal buffer is directly passed to the callback.
  • for disk based http data, a copy of the file content is passed to the callback and is immediately closed once the callback returns.
Parameters
<E>
the type of the exception thrown by the callback
callback:Helpers.ThrowingConsumer<Buffer, E>

The file item buffer callback

Annotations
@Override
Exceptions
IOException:
if the method can't load the buffer from disk