/** * Returns the size of the file content (in bytes). */ @Override protected long doGetContentSize() throws Exception { final Header header = method.getResponseHeader("content-length"); if (header == null) { // Assume 0 content-length return 0; } return Long.parseLong(header.getValue()); }
HeadMethod head = new HeadMethod("http://jakarta.apache.org"); // execute the method and handle any error responses. ... // Retrieve all the headers. Header[] headers = head.getResponseHeaders(); // Retrieve just the last modified header value. String lastModified = head.getResponseHeader("last-modified").getValue();
/** * Returns the size of the file content (in bytes). */ @Override protected long doGetContentSize() throws Exception { final Header header = method.getResponseHeader("content-length"); if (header == null) { // Assume 0 content-length return 0; } return Long.parseLong(header.getValue()); }
HeadMethod head = new HeadMethod("http://jakarta.apache.org"); // Excecute the method here with your HttpClient Header[] headers = head.getResponseHeaders(); String lastModified = head.getResponseHeader("last-modified").getValue();
/** * Returns the size of the file content (in bytes). */ @Override protected long doGetContentSize() throws Exception { final Header header = method.getResponseHeader("content-length"); if (header == null) { // Assume 0 content-length return 0; } return Long.parseLong(header.getValue()); }
/** * Returns the size of the file content (in bytes). */ protected long doGetContentSize() throws Exception { final Header header = method.getResponseHeader("content-length"); if (header == null) { // Assume 0 content-length return 0; } return Integer.parseInt(header.getValue()); }
/** * 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(); }
/** * 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"); FileSystemException.requireNonNull(header, "vfs.provider.http/last-modified.error", getName()); return DateUtil.parseDate(header.getValue()).getTime(); }
/** * 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(); }
/** * Returns the last modified time of this file. * <p/> * This implementation throws an exception. */ 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 DateParser.parseDate(header.getValue()).getTime(); }
int status = httpClient.executeMethod(headMethod); if (status == 200) { Header attachmentSizeHeader = headMethod.getResponseHeader("Content-Length"); if (attachmentSizeHeader != null) { attachmentSize = attachmentSizeHeader.getValue(); Header attachmentTypeHeader = headMethod.getResponseHeader("Content-Type"); if (attachmentTypeHeader != null) { attachmentType = attachmentTypeHeader.getValue();
/** Determine the value for the Content-Length header using a HEAD call * * @param url * @return * @throws HttpException */ public static int getContentLength(String url) throws HttpException, IOException { int result = 0; //Execute a GET method on the URL HeadMethod head = new HeadMethod(url); head.setFollowRedirects(true); head.addRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)"); try { _httpClient.executeMethod(head); // Retrieve just the Content-Length header value. String length = head.getResponseHeader("Content-Length").getValue(); result = Integer.parseInt(length); } catch (NumberFormatException nfe) { //header not found } finally { head.releaseConnection(); } return result; }
/** {@inheritDoc} */ public DateTime getLastModifiedTime() throws ResourceException { HeadMethod headMethod = new HeadMethod(resourceUrl); headMethod.addRequestHeader("Connection", "close"); try { httpClient.executeMethod(headMethod); if (headMethod.getStatusCode() != HttpStatus.SC_OK) { throw new ResourceException("Unable to retrieve resource URL " + resourceUrl + ", received HTTP status code " + headMethod.getStatusCode()); } Header lastModifiedHeader = headMethod.getResponseHeader("Last-Modified"); if (lastModifiedHeader != null && !DatatypeHelper.isEmpty(lastModifiedHeader.getValue())) { long lastModifiedTime = DateUtil.parseDate(lastModifiedHeader.getValue()).getTime(); return new DateTime(lastModifiedTime, ISOChronology.getInstanceUTC()); } return new DateTime(); } catch (IOException e) { throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e); } catch (DateParseException e) { throw new ResourceException("Unable to parse last modified date for resource:" + resourceUrl, e); } finally { headMethod.releaseConnection(); } }
try { httpClient.executeMethod(headMethod); if (headMethod.getResponseHeader("ETag") != null) { itemResult.etag = headMethod.getResponseHeader("ETag").getValue();
@Override public FileContentInfo create(final FileContent fileContent) throws FileSystemException { final HttpFileObject httpFile = (HttpFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile()); String contentType = null; String contentEncoding = null; HeadMethod headMethod; try { headMethod = httpFile.getHeadMethod(); } catch (final IOException e) { throw new FileSystemException(e); } final Header header = headMethod.getResponseHeader("content-type"); if (header != null) { final HeaderElement[] element = header.getElements(); if (element != null && element.length > 0) { contentType = element[0].getName(); } } contentEncoding = headMethod.getResponseCharSet(); return new DefaultFileContentInfo(contentType, contentEncoding); } }
@Override public FileContentInfo create(final FileContent fileContent) throws FileSystemException { String contentType = null; String contentEncoding = null; HeadMethod headMethod; try (final HttpFileObject<HttpFileSystem> httpFile = (HttpFileObject<HttpFileSystem>) FileObjectUtils .getAbstractFileObject(fileContent.getFile())) { headMethod = httpFile.getHeadMethod(); } catch (final IOException e) { throw new FileSystemException(e); } final Header header = headMethod.getResponseHeader("content-type"); if (header != null) { final HeaderElement[] element = header.getElements(); if (element != null && element.length > 0) { contentType = element[0].getName(); } } contentEncoding = headMethod.getResponseCharSet(); return new DefaultFileContentInfo(contentType, contentEncoding); } }
@Override public FileContentInfo create(final FileContent fileContent) throws FileSystemException { final HttpFileObject httpFile = (HttpFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile()); String contentType = null; String contentEncoding = null; HeadMethod headMethod; try { headMethod = httpFile.getHeadMethod(); } catch (final IOException e) { throw new FileSystemException(e); } final Header header = headMethod.getResponseHeader("content-type"); if (header != null) { final HeaderElement[] element = header.getElements(); if (element != null && element.length > 0) { contentType = element[0].getName(); } } contentEncoding = headMethod.getResponseCharSet(); return new DefaultFileContentInfo(contentType, contentEncoding); } }
public FileContentInfo create(FileContent fileContent) throws FileSystemException { HttpFileObject httpFile = (HttpFileObject) fileContent.getFile(); String contentType = null; String contentEncoding = null; Header header = httpFile.getHeadMethod().getResponseHeader("content-type"); if (header != null) { HeaderElement[] element; try { element = header.getValues(); } catch (HttpException e) { throw new FileSystemException(e); } if (element != null && element.length > 0) { contentType = element[0].getName(); } } contentEncoding = httpFile.getHeadMethod().getResponseCharSet(); return new DefaultFileContentInfo(contentType, contentEncoding); } }