public static void writeFromFile(NetcdfFile fileIn, String fileOutName) throws IOException, InvalidRangeException { FileOutputStream stream = new FileOutputStream(fileOutName); WritableByteChannel channel = stream.getChannel(); DataOutputStream dout = new DataOutputStream(Channels.newOutputStream(channel)); N3channelWriter writer = new N3channelWriter(fileIn); int numrec = fileIn.getUnlimitedDimension() == null ? 0 : fileIn.getUnlimitedDimension().getLength(); writer.writeHeader(dout, numrec); dout.flush(); writer.writeDataAll(channel); channel.close(); }
public static void writeFromFile(NetcdfFile fileIn, String fileOutName) throws IOException, InvalidRangeException { try (FileOutputStream stream = new FileOutputStream(fileOutName)) { WritableByteChannel channel = stream.getChannel(); DataOutputStream dout = new DataOutputStream(Channels.newOutputStream(channel)); N3channelWriter writer = new N3channelWriter(fileIn); int numrec = fileIn.getUnlimitedDimension() == null ? 0 : fileIn.getUnlimitedDimension().getLength(); writer.writeHeader(dout, numrec); dout.flush(); writer.writeDataAll(channel); } }
public static void writeFromFile(NetcdfFile fileIn, String fileOutName) throws IOException, InvalidRangeException { try (FileOutputStream stream = new FileOutputStream(fileOutName)) { WritableByteChannel channel = stream.getChannel(); DataOutputStream dout = new DataOutputStream(Channels.newOutputStream(channel)); N3channelWriter writer = new N3channelWriter(fileIn); int numrec = fileIn.getUnlimitedDimension() == null ? 0 : fileIn.getUnlimitedDimension().getLength(); writer.writeHeader(dout, numrec); dout.flush(); writer.writeDataAll(channel); } }
/** * Write ncfile to a WritableByteChannel. * * @param ncfile the file to write * @param wbc write to this WritableByteChannel. * If its a Socket, must have been opened through a call to java.nio.channels.SocketChannel.open() * @throws IOException on IO error * @throws InvalidRangeException range error */ public static void writeToChannel(NetcdfFile ncfile, WritableByteChannel wbc) throws IOException, InvalidRangeException { DataOutputStream stream = new DataOutputStream(new BufferedOutputStream( Channels.newOutputStream(wbc), 8000)); //DataOutputStream stream = new DataOutputStream(Channels.newOutputStream(wbc)); // buffering seems to improve by 5% N3channelWriter writer = new N3channelWriter(ncfile); int numrec = ncfile.getUnlimitedDimension() == null ? 0 : ncfile.getUnlimitedDimension().getLength(); writer.writeHeader(stream, numrec); stream.flush(); writer.writeDataAll(wbc); }
/** * Write ncfile to a WritableByteChannel. * * @param ncfile the file to write * @param wbc write to this WritableByteChannel. * If its a Socket, must have been opened through a call to java.nio.channels.SocketChannel.open() * @throws IOException on IO error * @throws InvalidRangeException range error */ public static void writeToChannel(NetcdfFile ncfile, WritableByteChannel wbc) throws IOException, InvalidRangeException { DataOutputStream stream = new DataOutputStream(new BufferedOutputStream( Channels.newOutputStream(wbc), 8000)); //DataOutputStream stream = new DataOutputStream(Channels.newOutputStream(wbc)); // buffering seems to improve by 5% N3channelWriter writer = new N3channelWriter(ncfile); int numrec = ncfile.getUnlimitedDimension() == null ? 0 : ncfile.getUnlimitedDimension().getLength(); writer.writeHeader(stream, numrec); stream.flush(); writer.writeDataAll(wbc); }
/** * Write ncfile to a WritableByteChannel. * * @param ncfile the file to write * @param wbc write to this WritableByteChannel. * If its a Socket, must have been opened through a call to java.nio.channels.SocketChannel.open() * @throws IOException on IO error * @throws InvalidRangeException range error */ public static void writeToChannel(NetcdfFile ncfile, WritableByteChannel wbc) throws IOException, InvalidRangeException { DataOutputStream stream = new DataOutputStream(new BufferedOutputStream( Channels.newOutputStream(wbc), 8000)); //DataOutputStream stream = new DataOutputStream(Channels.newOutputStream(wbc)); // buffering seems to improve by 5% N3channelWriter writer = new N3channelWriter(ncfile); int numrec = ncfile.getUnlimitedDimension() == null ? 0 : ncfile.getUnlimitedDimension().getLength(); writer.writeHeader(stream, numrec); stream.flush(); writer.writeDataAll(wbc); }