/** * Read the file and place contents into a byte array, * with any error messages put in the return String. * * @param filename the file to read from. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readFileToByteArray(String filename) throws IOException { try (FileInputStream fin = new FileInputStream(filename)) { InputStream in = new BufferedInputStream(fin); return readContentsToByteArray(in); } }
/** * Read the file and place contents into a byte array, * with any error messages put in the return String. * * @param filename the file to read from. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readFileToByteArray(String filename) throws IOException { try (FileInputStream fin = new FileInputStream(filename)) { InputStream in = new BufferedInputStream(fin); return readContentsToByteArray(in); } }
/** * Read the file and place contents into a byte array, * with any error messages put in the return String. * * @param filename the file to read from. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readFileToByteArray(String filename) throws IOException { InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(filename)); return readContentsToByteArray(in); } finally { if (in != null) in.close(); } }
/** * Read a remote CDM file into memory. All reads are then done from memory. * * @param uri location of CDM file, must be accessible through url.toURL().openStream(). * @return a NetcdfFile, which is completely in memory * @throws IOException if error reading file */ public static NetcdfFile openInMemory(URI uri) throws IOException { URL url = uri.toURL(); byte[] contents = IO.readContentsToByteArray(url.openStream()); return openInMemory(uri.toString(), contents); }
/** * Read a remote CDM file into memory. All reads are then done from memory. * * @param uri location of CDM file, must be accessible through url.toURL().openStream(). * @return a NetcdfFile, which is completely in memory * @throws IOException if error reading file */ public static NetcdfFile openInMemory(URI uri) throws IOException { URL url = uri.toURL(); byte[] contents = IO.readContentsToByteArray(url.openStream()); return openInMemory(uri.toString(), contents); }
/** * Read a remote CDM file into memory. All reads are then done from memory. * * @param uri location of CDM file, must be accessible through url.toURL().openStream(). * @return a NetcdfFile, which is completely in memory * @throws IOException if error reading file */ public static NetcdfFile openInMemory(URI uri) throws IOException { URL url = uri.toURL(); byte[] contents = IO.readContentsToByteArray(url.openStream()); return openInMemory(uri.toString(), contents); }