public boolean accept(File file) { if (!file.isFile()) { return false; } String type = getContentTypeFromName(file.getName()); String primary = type.substring(0, type.indexOf('/')); return accept.contains(type) || accept.contains(primary + "/*"); } });
public boolean accept(File file) { if (!file.isFile()) { return false; } String type = getContentTypeFromName(file.getName()); String primary = type.substring(0, type.indexOf('/')); return accept.contains(type) || accept.contains(primary + "/*"); } });
public void infoEntry(String href, String base, String accept, DataInfo 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; if (file.isFile()) { type = getContentTypeFromName(file.getName()); } else if (file.exists()) { type = null; } else { throw new FileNotFoundException(file.getAbsolutePath()); } handler.list(file.toURI(), type, file.lastModified()); } else { fallback.infoEntry(href, base, accept, handler); } }
public void infoEntry(String href, String base, String accept, DataInfo 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; if (file.isFile()) { type = getContentTypeFromName(file.getName()); } else if (file.exists()) { type = null; } else { throw new FileNotFoundException(file.getAbsolutePath()); } handler.list(file.toURI(), type, file.lastModified()); } else { fallback.infoEntry(href, base, accept, 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 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 listEachEntry(String href, String base, String accept, DataInfo 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); if (!file.canRead()) { throw XProcException.stepError(12); } if (file.isDirectory()) { for (File f : listAcceptableFiles(file, accept)) { String type; if (f.isDirectory()) { type = null; } else { type = getContentTypeFromName(f.getName()); } handler.list(f.toURI(), type, f.lastModified()); } } else { throw new FileNotFoundException(file.getAbsolutePath() + " is not a directory"); } } else { fallback.listEachEntry(href, base, accept, handler); } }
public void listEachEntry(String href, String base, String accept, DataInfo 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); if (!file.canRead()) { throw XProcException.stepError(12); } if (file.isDirectory()) { for (File f : listAcceptableFiles(file, accept)) { String type; if (f.isDirectory()) { type = null; } else { type = getContentTypeFromName(f.getName()); } handler.list(f.toURI(), type, f.lastModified()); } } else { throw new FileNotFoundException(file.getAbsolutePath() + " is not a directory"); } } else { fallback.listEachEntry(href, base, accept, handler); } }
public void testGetContentTypeFromName() throws IOException { assertEquals("text/plain", store.getContentTypeFromName(".txt")); assertEquals("application/xml", store.getContentTypeFromName(".xml")); assertEquals("application/json", store.getContentTypeFromName(".json")); assertEquals("application/zip", store.getContentTypeFromName(".zip")); }