Class Http4FileObject<FS extends Http4FileSystem>
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractFileObject<FS>
-
- org.apache.commons.vfs2.provider.http4.Http4FileObject<FS>
-
- Type Parameters:
FS
- AnHttp4FileSystem
subclass
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Comparable<FileObject>
,java.lang.Iterable<FileObject>
,FileObject
public class Http4FileObject<FS extends Http4FileSystem> extends AbstractFileObject<FS>
A file object backed by Apache HttpComponents HttpClient.- Since:
- 2.3
-
-
Field Summary
Fields Modifier and Type Field Description private java.net.URI
internalURI
Internal URI mapped to thisFileObject
.private org.apache.http.HttpResponse
lastHeadResponse
The last executed HEADHttpResponse
object.private java.lang.String
urlCharset
URL charset string.-
Fields inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
DEFAULT_BUFFER_SIZE
-
Fields inherited from interface org.apache.commons.vfs2.FileObject
EMPTY_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Http4FileObject(AbstractFileName name, FS fileSystem)
ConstructHttp4FileObject
.protected
Http4FileObject(AbstractFileName name, FS fileSystem, Http4FileSystemConfigBuilder builder)
ConstructHttp4FileObject
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doDetach()
Detaches this file object from its file resource.protected long
doGetContentSize()
Returns the size of the file content (in bytes).protected java.io.InputStream
doGetInputStream(int bufferSize)
Creates an input stream to read the file content from.protected long
doGetLastModifiedTime()
Returns the last modified time of this file.protected RandomAccessContent
doGetRandomAccessContent(RandomAccessMode mode)
Creates access to the file for random i/o.protected FileType
doGetType()
Determines the type of this file.protected boolean
doIsWriteable()
Determines if this file can be written to.protected java.lang.String[]
doListChildren()
Lists the children of this file.protected org.apache.http.HttpResponse
executeHttpUriRequest(org.apache.http.client.methods.HttpUriRequest httpRequest)
Execute the request using the givenhttpRequest
and return aHttpResponse
from the execution.protected FileContentInfoFactory
getFileContentInfoFactory()
Creates the FileContentInfo factory.protected java.net.URI
getInternalURI()
Return the internalURI
object mapped to this file object.(package private) org.apache.http.HttpResponse
getLastHeadResponse()
Return the last executed HEADHttpResponse
object.protected java.lang.String
getUrlCharset()
Return URL charset string.-
Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
canRenameTo, childrenChanged, close, compareTo, copyFrom, createFile, createFolder, delete, delete, deleteAll, doAttach, doCreateFileContent, doCreateFolder, doDelete, doGetAttributes, doGetCertificates, doGetInputStream, doGetOutputStream, doIsExecutable, doIsHidden, doIsReadable, doIsSameFile, doIsSymbolicLink, doListChildrenResolved, doRemoveAttribute, doRename, doSetAttribute, doSetExecutable, doSetLastModifiedTime, doSetReadable, doSetWritable, endOutput, exists, finalize, findFiles, findFiles, getAbstractFileSystem, getChild, getChildren, getContent, getFileOperations, getFileSystem, getInputStream, getInputStream, getName, getOutputStream, getOutputStream, getParent, getPublicURIString, getRandomAccessContent, getType, getURL, handleChanged, handleCreate, handleDelete, holdObject, injectType, isAttached, isContentOpen, isExecutable, isFile, isFolder, isHidden, isReadable, isSameFile, isSymbolicLink, isWriteable, iterator, listFiles, moveTo, notifyAllStreamsClosed, onChange, onChildrenChanged, refresh, resolveFile, resolveFile, setExecutable, setReadable, setWritable, toString
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.vfs2.FileObject
getPath, getURI
-
-
-
-
Field Detail
-
urlCharset
private final java.lang.String urlCharset
URL charset string.
-
internalURI
private final java.net.URI internalURI
Internal URI mapped to thisFileObject
. For example, the internal URI ofhttp4://example.com/a.txt
ishttp://example.com/a.txt
.
-
lastHeadResponse
private org.apache.http.HttpResponse lastHeadResponse
The last executed HEADHttpResponse
object.
-
-
Constructor Detail
-
Http4FileObject
protected Http4FileObject(AbstractFileName name, FS fileSystem) throws FileSystemException
ConstructHttp4FileObject
.- Parameters:
name
- file namefileSystem
- file system- Throws:
FileSystemException
- if any error occurs
-
Http4FileObject
protected Http4FileObject(AbstractFileName name, FS fileSystem, Http4FileSystemConfigBuilder builder) throws FileSystemException
ConstructHttp4FileObject
.- Parameters:
name
- file namefileSystem
- file systembuilder
-Http4FileSystemConfigBuilder
object- Throws:
FileSystemException
- if any error occurs
-
-
Method Detail
-
doDetach
protected void doDetach() throws java.lang.Exception
Description copied from class:AbstractFileObject
Detaches this file object from its file resource.Called when this file is closed. Note that the file object may be reused later, so should be able to be reattached.
This implementation does nothing.
- Overrides:
doDetach
in classAbstractFileObject<FS extends Http4FileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetContentSize
protected long doGetContentSize() throws java.lang.Exception
Description copied from class:AbstractFileObject
Returns the size of the file content (in bytes). Is only called ifAbstractFileObject.doGetType()
returnsFileType.FILE
.- Specified by:
doGetContentSize
in classAbstractFileObject<FS extends Http4FileSystem>
- Returns:
- The size of the file in bytes.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetInputStream
protected java.io.InputStream doGetInputStream(int bufferSize) throws java.lang.Exception
Description copied from class:AbstractFileObject
Creates an input stream to read the file content from. Is only called ifAbstractFileObject.doGetType()
returnsFileType.FILE
.It is guaranteed that there are no open output streams for this file when this method is called.
The returned stream does not have to be buffered.
- Overrides:
doGetInputStream
in classAbstractFileObject<FS extends Http4FileSystem>
- Parameters:
bufferSize
- Buffer size hint.- Returns:
- An InputStream to read the file content.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetLastModifiedTime
protected long doGetLastModifiedTime() throws java.lang.Exception
Description copied from class:AbstractFileObject
Returns the last modified time of this file. Is only called ifAbstractFileObject.doGetType()
does not returnThis implementation throws an exception.
- Overrides:
doGetLastModifiedTime
in classAbstractFileObject<FS extends Http4FileSystem>
- Returns:
- The last modification time.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetRandomAccessContent
protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode) throws java.lang.Exception
Description copied from class:AbstractFileObject
Creates access to the file for random i/o. Is only called ifAbstractFileObject.doGetType()
returnsFileType.FILE
.It is guaranteed that there are no open output streams for this file when this method is called.
- Overrides:
doGetRandomAccessContent
in classAbstractFileObject<FS extends Http4FileSystem>
- Parameters:
mode
- The mode to access the file.- Returns:
- The RandomAccessContext.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetType
protected FileType doGetType() throws java.lang.Exception
Description copied from class:AbstractFileObject
Determines the type of this file. Must not return null. The return value of this method is cached, so the implementation can be expensive.- Specified by:
doGetType
in classAbstractFileObject<FS extends Http4FileSystem>
- Returns:
- the type of the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
doIsWriteable
protected boolean doIsWriteable() throws java.lang.Exception
Description copied from class:AbstractFileObject
Determines if this file can be written to. Is only called ifAbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation always returns true.
- Overrides:
doIsWriteable
in classAbstractFileObject<FS extends Http4FileSystem>
- Returns:
- true if the file is writable.
- Throws:
java.lang.Exception
- if an error occurs.
-
doListChildren
protected java.lang.String[] doListChildren() throws java.lang.Exception
Description copied from class:AbstractFileObject
Lists the children of this file. Is only called ifAbstractFileObject.doGetType()
returnsFileType.FOLDER
. The return value of this method is cached, so the implementation can be expensive.- Specified by:
doListChildren
in classAbstractFileObject<FS extends Http4FileSystem>
- Returns:
- a possible empty String array if the file is a directory or null or an exception if the file is not a directory or can't be read.
- Throws:
java.lang.Exception
- if an error occurs.
-
executeHttpUriRequest
protected org.apache.http.HttpResponse executeHttpUriRequest(org.apache.http.client.methods.HttpUriRequest httpRequest) throws java.io.IOException
Execute the request using the givenhttpRequest
and return aHttpResponse
from the execution.- Parameters:
httpRequest
-HttpUriRequest
object- Returns:
HttpResponse
from the execution- Throws:
java.io.IOException
- if IO error occurs- Since:
- 2.5.0
-
getFileContentInfoFactory
protected FileContentInfoFactory getFileContentInfoFactory()
Description copied from class:AbstractFileObject
Creates the FileContentInfo factory.- Overrides:
getFileContentInfoFactory
in classAbstractFileObject<FS extends Http4FileSystem>
- Returns:
- The FileContentInfoFactory.
-
getInternalURI
protected java.net.URI getInternalURI()
Return the internalURI
object mapped to this file object.- Returns:
- the internal
URI
object mapped to this file object
-
getLastHeadResponse
org.apache.http.HttpResponse getLastHeadResponse() throws java.io.IOException
Return the last executed HEADHttpResponse
object.- Returns:
- the last executed HEAD
HttpResponse
object - Throws:
java.io.IOException
- if IO error occurs
-
getUrlCharset
protected java.lang.String getUrlCharset()
Return URL charset string.- Returns:
- URL charset string
-
-