/** * Wite the contents from the String to a Stream, * * @param contents String holding the contents. * @param os write to this OutputStream * @throws java.io.IOException on io error */ static public void writeContents(String contents, OutputStream os) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(contents.getBytes(CDM.utf8Charset)); IO.copy(bin, os); }
static private String readContents(InputStream is, String charset, int maxKbytes) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(1000 * maxKbytes); IO.copy(is, bout, 1000 * maxKbytes); return bout.toString(charset); }
/** * Read the contents from the inputStream and place into a String, * with any error messages put in the return String. * * @param is the inputStream to read from. * @return String holding the contents, or an error message. * @throws java.io.IOException on io error */ static public String readContents(InputStream is, String charset) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(10 * default_file_buffersize); IO.copy(is, bout); return bout.toString(charset); }
static public long appendToFile(InputStream in, String fileOutName) throws IOException { try (FileOutputStream fout = new FileOutputStream( fileOutName)) { OutputStream out = new BufferedOutputStream(fout); return IO.copy(in, out); } }
static public long appendToFile(InputStream in, String fileOutName) throws IOException { try (FileOutputStream fout = new FileOutputStream( fileOutName)) { OutputStream out = new BufferedOutputStream(fout); return IO.copy(in, out); } }
/** * Wite the contents from the String to a Stream, * * @param contents String holding the contents. * @param os write to this OutputStream * @throws java.io.IOException on io error */ static public void writeContents(String contents, OutputStream os) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(contents.getBytes(CDM.utf8Charset)); IO.copy(bin, os); }
/** * Wite the contents from the String to a Stream, * * @param contents String holding the contents. * @param os write to this OutputStream * @throws java.io.IOException on io error */ static public void writeContents(String contents, OutputStream os) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(contents.getBytes(CDM.utf8Charset)); IO.copy(bin, os); }
/** * Read the contents from the inputStream and place into a String, * with any error messages put in the return String. * * @param is the inputStream to read from. * @return String holding the contents, or an error message. * @throws java.io.IOException on io error */ static public String readContents(InputStream is, String charset) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(10 * default_file_buffersize); IO.copy(is, bout); return bout.toString(charset); }
/** * Read the contents from the inputStream and place into a byte array, * with any error messages put in the return String. * * @param is the inputStream to read from. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readContentsToByteArray(InputStream is) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(10 * default_file_buffersize); IO.copy(is, bout); return bout.toByteArray(); }
/** * Read the contents from the inputStream and place into a byte array, * with any error messages put in the return String. * * @param is the inputStream to read from. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readContentsToByteArray(InputStream is) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(10 * default_file_buffersize); IO.copy(is, bout); return bout.toByteArray(); }
/** * Read the contents from the inputStream and place into a String, * with any error messages put in the return String. * * @param is the inputStream to read from. * @return String holding the contents, or an error message. * @throws java.io.IOException on io error */ static public String readContents(InputStream is, String charset) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(10 * default_file_buffersize); IO.copy(is, bout); return bout.toString(charset); }
/** * Read the contents from the inputStream and place into a byte array, * with any error messages put in the return String. * * @param is the inputStream to read from. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readContentsToByteArray(InputStream is) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(10 * default_file_buffersize); IO.copy(is, bout); return bout.toByteArray(); }
static public long appendToFile(InputStream in, String fileOutName) throws IOException { OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(fileOutName, true)); return IO.copy(in, out); } finally { if (null != in) in.close(); if (null != out) out.close(); } }
/** * copy input stream to file. close input stream when done. * * @param in copy from here * @param fileOutName open this file (overwrite) and copy to it. * @return number of bytes copied * @throws java.io.IOException on io error */ static public long writeToFile(InputStream in, String fileOutName) throws IOException { try (FileOutputStream fout = new FileOutputStream( fileOutName)) { OutputStream out = new BufferedOutputStream(fout); return IO.copy(in, out); } finally { if (null != in) in.close(); } }
/** * copy file to output stream * * @param src source * @param fileOut copy to this file * @throws java.io.IOException on io error */ static public void copy2File(byte[] src, String fileOut) throws IOException { try (FileOutputStream fout = new FileOutputStream(fileOut)) { InputStream in = new BufferedInputStream( new ByteArrayInputStream(src)); OutputStream out = new BufferedOutputStream(fout); IO.copy(in, out); } }
/** * copy one file to another. * * @param fileIn copy from this file, which must exist. * @param fileOut copy to this file, which is overrwritten if already exists. * @throws java.io.IOException on io error */ static public void copyFile(File fileIn, File fileOut) throws IOException { try (FileInputStream fin = new FileInputStream(fileIn); FileOutputStream fout = new FileOutputStream(fileOut)) { InputStream in = new BufferedInputStream(fin); OutputStream out = new BufferedOutputStream(fout); IO.copy(in, out); } }
/** * copy one file to another. * * @param fileInName copy from this file, which must exist. * @param fileOutName copy to this file, which is overrwritten if already exists. * @throws java.io.IOException on io error */ static public void copyFile(String fileInName, String fileOutName) throws IOException { try (FileInputStream fin = new FileInputStream(fileInName); FileOutputStream fout = new FileOutputStream(fileOutName)) { InputStream in = new BufferedInputStream(fin); OutputStream out = new BufferedOutputStream(fout); IO.copy(in, out); } }
/** testing */ public static void main(String args[]) throws IOException { InputStream is = new FileInputStream( "C:\\Users\\caron\\.unidata\\NetcdfUI22.xml"); XMLStore store = new XMLStore(); IO.copy(is, System.out); is.close(); }
/** * inflate data * * @param compressed compressed data * @return uncompressed data * @throws IOException on I/O error */ private byte[] inflate(byte[] compressed) throws IOException { // run it through the Inflator ByteArrayInputStream in = new ByteArrayInputStream(compressed); java.util.zip.InflaterInputStream inflater = new java.util.zip.InflaterInputStream(in); ByteArrayOutputStream out = new ByteArrayOutputStream(8 * compressed.length); IO.copy(inflater, out); byte[] uncomp = out.toByteArray(); if (debug) System.out.println(" inflate bytes in= " + compressed.length + " bytes out= " + uncomp.length); return uncomp; }
/** * Read a local CDM file into memory. All reads are then done from memory. * * @param filename location of CDM file, must be a local file. * @return a NetcdfFile, which is completely in memory * @throws IOException if error reading file */ public static NetcdfFile openInMemory(String filename) throws IOException { File file = new File(filename); ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); InputStream in = new BufferedInputStream(new FileInputStream(filename)); IO.copy(in, bos); return openInMemory(filename, bos.toByteArray()); }