public void readEntry(String href, String base, String accept, String overrideContentType, DataReader handler) throws MalformedURLException, FileNotFoundException, IOException { URI baseURI = URI.create(base); URL url = baseURI.resolve(href).toURL(); URLConnection connection = url.openConnection(); connection.setRequestProperty("Accept", accept); final InputStream stream = connection.getInputStream(); try { String type = connection.getContentType(); if (overrideContentType != null) { type = overrideContentType; } URI id = URI.create(connection.getURL().toExternalForm()); long len = 0; // Call getContentLengthLong if it's available try { Method lenMethod = connection.getClass().getDeclaredMethod("getContentLengthLong"); lenMethod.invoke(connection); } catch (Exception e) { // Whatever... len = connection.getContentLength(); } handler.load(id, type, stream, len); } finally { stream.close(); } }
public void readEntry(String href, String base, String accept, String overrideContentType, DataReader handler) throws MalformedURLException, FileNotFoundException, IOException { URI baseURI = URI.create(base); URL url = baseURI.resolve(href).toURL(); URLConnection connection = url.openConnection(); connection.setRequestProperty("Accept", accept); final InputStream stream = connection.getInputStream(); try { String type = connection.getContentType(); if (overrideContentType != null) { type = overrideContentType; } URI id = URI.create(connection.getURL().toExternalForm()); long len = 0; // Call getContentLengthLong if it's available try { Method lenMethod = connection.getClass().getDeclaredMethod("getContentLengthLong"); lenMethod.invoke(connection); } catch (Exception e) { // Whatever... len = connection.getContentLength(); } handler.load(id, type, stream, len); } finally { stream.close(); } }
public void readEntry(String href, String base, String accept, String overrideContentType, DataReader handler) throws MalformedURLException, FileNotFoundException, IOException { URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { File file = URIUtils.toFile(uri); String type = getContentTypeFromName(file.getName()); if (overrideContentType != null) { type = overrideContentType; } InputStream in = new FileInputStream(file); try { handler.load(file.toURI(), type, in, file.length()); } finally { in.close(); } } else { fallback.readEntry(href, base, accept, overrideContentType, handler); } }
public void readEntry(String href, String base, String accept, String overrideContentType, DataReader handler) throws MalformedURLException, FileNotFoundException, IOException { URI baseURI = URI.create(base); URI uri = baseURI.resolve(href); if ("file".equalsIgnoreCase(uri.getScheme())) { File file = URIUtils.toFile(uri); String type = getContentTypeFromName(file.getName()); if (overrideContentType != null) { type = overrideContentType; } InputStream in = new FileInputStream(file); try { handler.load(file.toURI(), type, in, file.length()); } finally { in.close(); } } else { fallback.readEntry(href, base, accept, overrideContentType, handler); } }
public Void handleResponse(HttpResponse response) throws IOException { URI contentId = getContentId(localContext); HttpEntity entity = response.getEntity(); Header hd = entity.getContentType(); String type = null; if (hd != null) { type = hd.getValue(); } if (overrideContentType != null) { type = overrideContentType; } handler.load(contentId, type, entity.getContent(), entity.getContentLength()); return null; } }, localContext);
public Void handleResponse(HttpResponse response) throws IOException { URI contentId = getContentId(localContext); HttpEntity entity = response.getEntity(); Header hd = entity.getContentType(); String type = null; if (hd != null) { type = hd.getValue(); } if (overrideContentType != null) { type = overrideContentType; } handler.load(contentId, type, entity.getContent(), entity.getContentLength()); return null; } }, localContext);