Class HttpFileImpl
- java.lang.Object
-
- net.officefloor.web.resource.impl.AbstractHttpResource
-
- net.officefloor.web.resource.impl.HttpFileImpl
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,FileCompleteCallback
,HttpFile
,HttpResource
public class HttpFileImpl extends AbstractHttpResource implements HttpFile, FileCompleteCallback
AbstractHttpFile
implementation.- Author:
- Daniel Sagenschneider
-
-
Field Summary
-
Fields inherited from class net.officefloor.web.resource.impl.AbstractHttpResource
path
-
-
Constructor Summary
Constructors Constructor Description HttpFileImpl(java.lang.String path, java.nio.file.Path cleanupResourcePath, java.nio.channels.FileChannel file, HttpHeaderValue contentEncoding, HttpHeaderValue contentType, java.nio.charset.Charset charset)
Initiate an existingHttpFile
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
complete(java.nio.channels.FileChannel file, boolean isWritten)
Invoked on completion of writing theFileChannel
content.java.nio.charset.Charset
getCharset()
Obtains theCharset
for the contents.HttpHeaderValue
getContentEncoding()
Obtains theContent-Encoding
for thisHttpFile
.HttpHeaderValue
getContentType()
Obtains theContent-Type
for thisHttpFile
.boolean
isExist()
Indicates if thisHttpResource
exists.void
writeTo(HttpResponse response)
Writes theHttpFile
to theHttpResponse
.-
Methods inherited from class net.officefloor.web.resource.impl.AbstractHttpResource
equals, getPath, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.officefloor.web.resource.HttpResource
getPath
-
-
-
-
Constructor Detail
-
HttpFileImpl
public HttpFileImpl(java.lang.String path, java.nio.file.Path cleanupResourcePath, java.nio.channels.FileChannel file, HttpHeaderValue contentEncoding, HttpHeaderValue contentType, java.nio.charset.Charset charset)
Initiate an existingHttpFile
.- Parameters:
path
- Path.cleanupResourcePath
- ResourcePath
to clean up. May benull
.file
-FileChannel
to the file.contentEncoding
-Content-Encoding
.contentType
-Content-Type
.charset
-Charset
.
-
-
Method Detail
-
isExist
public boolean isExist()
Description copied from interface:HttpResource
Indicates if this
HttpResource
exists. Should thisHttpResource
not exist, only the path will be available.This allows for caching of
HttpResource
instances not existing.- Specified by:
isExist
in interfaceHttpResource
- Returns:
true
if thisHttpResource
exists.
-
getContentEncoding
public HttpHeaderValue getContentEncoding()
Description copied from interface:HttpFile
Obtains theContent-Encoding
for thisHttpFile
.- Specified by:
getContentEncoding
in interfaceHttpFile
- Returns:
Content-Encoding
for thisHttpFile
.- See Also:
ResourceTransformer
-
getContentType
public HttpHeaderValue getContentType()
Description copied from interface:HttpFile
Obtains theContent-Type
for thisHttpFile
.- Specified by:
getContentType
in interfaceHttpFile
- Returns:
Content-Type
for thisHttpFile
.- See Also:
FileTypeDetector
-
getCharset
public java.nio.charset.Charset getCharset()
Description copied from interface:HttpFile
Obtains theCharset
for the contents.- Specified by:
getCharset
in interfaceHttpFile
- Returns:
Charset
ornull
if contents are not text or theCharset
is unknown.- See Also:
ResourceSystem
,ResourceSystemContext
-
writeTo
public void writeTo(HttpResponse response) throws java.io.IOException
Writes theHttpFile
to theHttpResponse
.- Specified by:
writeTo
in interfaceHttpFile
- Parameters:
response
-HttpResponse
- Throws:
java.io.IOException
- If fails to write theHttpFile
.
-
complete
public void complete(java.nio.channels.FileChannel file, boolean isWritten) throws java.io.IOException
Description copied from interface:FileCompleteCallback
Invoked on completion of writing the
FileChannel
content.Note that may also be invoked if content was not written (rather cancelled).
Typical use is to close the
FileChannel
once complete.WARNING: this is typically invoked on the
SocketChannel
Thread
so should not invoke any long running operations.- Specified by:
complete
in interfaceFileCompleteCallback
- Parameters:
file
-FileChannel
from the write.isWritten
-true
indicates whether written, whilefalse
indicates cancelled.- Throws:
java.io.IOException
- If issue in interacting withFileChannel
.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-