Author: ggregory Date: Wed Feb 6 15:13:44 2013 New Revision: 1443005 URL: http://svn.apache.org/viewvc?rev=1443005&view=rev Log: Sort methods in AB order.
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java?rev=1443005&r1=1443004&r2=1443005&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileObject.java Wed Feb 6 15:13:44 2013 @@ -49,8 +49,32 @@ import org.apache.commons.vfs2.util.Rand */ public class HttpFileObject<FS extends HttpFileSystem> extends AbstractFileObject<FS> { + /** + * An InputStream that cleans up the HTTP connection on close. + */ + static class HttpInputStream extends MonitorInputStream + { + private final GetMethod method; + + public HttpInputStream(final GetMethod method) + throws IOException + { + super(method.getResponseBodyAsStream()); + this.method = method; + } + + /** + * Called after the stream has been closed. + */ + @Override + protected void onClose() throws IOException + { + method.releaseConnection(); + } + } private final String urlCharset; private final boolean followRedirect; + private HeadMethod method; protected HttpFileObject(final AbstractFileName name, final FS fileSystem) @@ -76,39 +100,6 @@ public class HttpFileObject<FS extends H } /** - * Determines the type of this file. Must not return null. The return - * value of this method is cached, so the implementation can be expensive. - */ - @Override - protected FileType doGetType() throws Exception - { - // Use the HEAD method to probe the file. - final int status = this.getHeadMethod().getStatusCode(); - if (status == HttpURLConnection.HTTP_OK) - { - return FileType.FILE; - } - else if (status == HttpURLConnection.HTTP_NOT_FOUND - || status == HttpURLConnection.HTTP_GONE) - { - return FileType.IMAGINARY; - } - else - { - throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); - } - } - - /** - * Lists the children of this file. - */ - @Override - protected String[] doListChildren() throws Exception - { - throw new Exception("Not implemented."); - } - - /** * Returns the size of the file content (in bytes). */ @Override @@ -124,22 +115,6 @@ public class HttpFileObject<FS extends H } /** - * Returns the last modified time of this file. - * <p/> - * This implementation throws an exception. - */ - @Override - protected long doGetLastModifiedTime() throws Exception - { - final Header header = method.getResponseHeader("last-modified"); - if (header == null) - { - throw new FileSystemException("vfs.provider.http/last-modified.error", getName()); - } - return DateUtil.parseDate(header.getValue()).getTime(); - } - - /** * Creates an input stream to read the file content from. Is only called * if {@link #doGetType} returns {@link FileType#FILE}. * <p/> @@ -166,54 +141,65 @@ public class HttpFileObject<FS extends H return new HttpInputStream(getMethod); } - @Override - protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception - { - return new HttpRandomAccessContent(this, mode); - } - /** - * Prepares a HttpMethod object. - * - * @since 2.0 (was package) + * Returns the last modified time of this file. + * <p/> + * This implementation throws an exception. */ - protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException + @Override + protected long doGetLastModifiedTime() throws Exception { - final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset()); - method.setPath(pathEncoded); - method.setFollowRedirects(this.getFollowRedirect()); - method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS"); + final Header header = method.getResponseHeader("last-modified"); + if (header == null) + { + throw new FileSystemException("vfs.provider.http/last-modified.error", getName()); + } + return DateUtil.parseDate(header.getValue()).getTime(); } - protected String encodePath(final String decodedPath) throws URIException + @Override + protected RandomAccessContent doGetRandomAccessContent(final RandomAccessMode mode) throws Exception { - return URIUtil.encodePath(decodedPath); + return new HttpRandomAccessContent(this, mode); } /** - * An InputStream that cleans up the HTTP connection on close. + * Determines the type of this file. Must not return null. The return + * value of this method is cached, so the implementation can be expensive. */ - static class HttpInputStream extends MonitorInputStream + @Override + protected FileType doGetType() throws Exception { - private final GetMethod method; - - public HttpInputStream(final GetMethod method) - throws IOException + // Use the HEAD method to probe the file. + final int status = this.getHeadMethod().getStatusCode(); + if (status == HttpURLConnection.HTTP_OK) { - super(method.getResponseBodyAsStream()); - this.method = method; + return FileType.FILE; } - - /** - * Called after the stream has been closed. - */ - @Override - protected void onClose() throws IOException + else if (status == HttpURLConnection.HTTP_NOT_FOUND + || status == HttpURLConnection.HTTP_GONE) { - method.releaseConnection(); + return FileType.IMAGINARY; + } + else + { + throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); } } + /** + * Lists the children of this file. + */ + @Override + protected String[] doListChildren() throws Exception + { + throw new Exception("Not implemented."); + } + + protected String encodePath(final String decodedPath) throws URIException + { + return URIUtil.encodePath(decodedPath); + } @Override protected FileContentInfoFactory getFileContentInfoFactory() @@ -221,16 +207,12 @@ public class HttpFileObject<FS extends H return new HttpFileContentInfoFactory(); } + protected boolean getFollowRedirect() { return followRedirect; } - protected String getUrlCharset() - { - return urlCharset; - } - HeadMethod getHeadMethod() throws IOException { if (method != null) @@ -245,6 +227,24 @@ public class HttpFileObject<FS extends H return method; } + protected String getUrlCharset() + { + return urlCharset; + } + + /** + * Prepares a HttpMethod object. + * + * @since 2.0 (was package) + */ + protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException + { + final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset()); + method.setPath(pathEncoded); + method.setFollowRedirects(this.getFollowRedirect()); + method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS"); + } + /* protected Map doGetAttributes() throws Exception {