@Override public ByteBuffer readBytes() throws IOException { try (FileInputStream in = openStream(); FileChannel fc = in.getChannel()) { ByteBuffer buf = ByteBuffer.allocateDirect((int)fc.size()); // no >2GB files fc.read(buf); buf.flip(); return buf; } } }
/** * Attempts to locate the resource at the given path, and returns a wrapper which allows its data * to be efficiently read. * * <p>First, the path prefix is prepended (see {@link #setPathPrefix(String)}) and the the class * loader checked. If not found, then the extra directories, if any, are checked, in order. If * the file is not found in any of the extra directories either, then an exception is thrown. */ protected Resource requireResource(String path) throws IOException { URL url = getClass().getClassLoader().getResource(pathPrefix + path); if (url != null) { return url.getProtocol().equals("file") ? new FileResource(new File(URLDecoder.decode(url.getPath(), "UTF-8"))) : new URLResource(url); } for (File dir : directories) { File f = new File(dir, path).getCanonicalFile(); if (f.exists()) { return new FileResource(f); } } throw new FileNotFoundException(path); }
/** * Attempts to locate the resource at the given path, and returns a wrapper which allows its data * to be efficiently read. * * <p>First, the path prefix is prepended (see {@link #setPathPrefix(String)}) and the the class * loader checked. If not found, then the extra directories, if any, are checked, in order. If * the file is not found in any of the extra directories either, then an exception is thrown. */ protected Resource requireResource(String path) throws IOException { URL url = getClass().getClassLoader().getResource(pathPrefix + path); if (url != null) { return url.getProtocol().equals("file") ? new FileResource(new File(url.getPath())) : new URLResource(url); } for (File dir : directories) { File f = new File(dir, path).getCanonicalFile(); if (f.exists()) { return new FileResource(f); } } throw new FileNotFoundException(path); }
/** * Attempts to locate the resource at the given path, and returns a wrapper which allows its data * to be efficiently read. * * <p>First, the path prefix is prepended (see {@link #setPathPrefix(String)}) and the the class * loader checked. If not found, then the extra directories, if any, are checked, in order. If * the file is not found in any of the extra directories either, then an exception is thrown. */ protected Resource requireResource(String path) throws IOException { URL url = getClass().getClassLoader().getResource(pathPrefix + path); if (url != null) { return url.getProtocol().equals("file") ? new FileResource(new File(URLDecoder.decode(url.getPath(), "UTF-8"))) : new URLResource(url); } for (File dir : directories) { File f = new File(dir, path).getCanonicalFile(); if (f.exists()) { return new FileResource(f); } } throw new FileNotFoundException(path); }
/** * Attempts to locate the resource at the given path, and returns a wrapper which allows its data * to be efficiently read. * * <p>First, the path prefix is prepended (see {@link #setPathPrefix(String)}) and the the class * loader checked. If not found, then the extra directories, if any, are checked, in order. If * the file is not found in any of the extra directories either, then an exception is thrown. */ protected Resource requireResource(String path) throws IOException { URL url = getClass().getClassLoader().getResource(pathPrefix + path); if (url != null) { return url.getProtocol().equals("file") ? new FileResource(new File(url.getPath())) : new URLResource(url); } for (File dir : directories) { File f = new File(dir, path).getCanonicalFile(); if (f.exists()) { return new FileResource(f); } } throw new FileNotFoundException(path); }
@Override public ByteBuffer readBytes() throws IOException { try (FileInputStream in = openStream(); FileChannel fc = in.getChannel()) { ByteBuffer buf = ByteBuffer.allocateDirect((int)fc.size()); // no >2GB files fc.read(buf); buf.flip(); return buf; } } }
@Override public byte[] readBytes() throws IOException { InputStream in = openStream(); try { byte[] buffer = new byte[(int)file.length()]; // no >2GB files in.read(buffer); return buffer; } finally { in.close(); } } }
@Override public byte[] readBytes() throws IOException { InputStream in = openStream(); try { byte[] buffer = new byte[(int)file.length()]; // no >2GB files in.read(buffer); return buffer; } finally { in.close(); } } }