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); } }
int nbytes = (int) v.readToByteChannel(v.getShapeAsSection(), channel); filePos += nbytes; filePos += pad(channel, nbytes); if (debugPos) System.out.println(" vinfo="+vinfo);
@Test public void testN3channelWriter() throws IOException, InvalidRangeException { System.out.println("\nFile= " + endpoint + " size=" + new File(endpoint).length()); NetcdfFile fileIn = NetcdfFile.open(endpoint); long start = System.currentTimeMillis(); String fileOut = tempFolder.newFile().getAbsolutePath(); N3channelWriter.writeFromFile(fileIn, fileOut); long took = System.currentTimeMillis() - start; System.out.println("N3streamWriter took " + took + " msecs"); NetcdfFile file2 = NetcdfFile.open(fileOut); assert ucar.unidata.util.test.CompareNetcdf.compareFiles(fileIn, file2, true, false, false); fileIn.close(); file2.close(); System.out.println("N3channelWriter took " + took + " msecs"); }
int nbytes = (int) v.readToByteChannel(v.getShapeAsSection(), channel); filePos += nbytes; filePos += pad(channel, nbytes); if (debugPos) System.out.println(" vinfo="+vinfo);
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(); }
filePos += pad(channel, nbytes); if (debugPos) System.out.printf(" read=%d vinfo=%s%n", nbytes, vinfo);
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); }