@Test public void writeNcStream() throws IOException, InvalidRangeException { String outFile = tempFolder.newFile().getAbsolutePath(); try (NetcdfFile ncfile = NetcdfDatasets.openFile(filename, null)) { NcStreamWriter writer = new NcStreamWriter(ncfile, null); try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile), 50 * 1000)) { writer.streamAll(fos); } try (NetcdfFile copy = NetcdfDatasets.openFile(outFile, null)) { Formatter errs = new Formatter(); CompareNetcdf2 compare = new CompareNetcdf2(errs, true, true, true); boolean ok = compare.compare(ncfile, copy); if (!ok) { System.out.printf("FAIL %s%n", errs); fail(); } } } }
public long streamAll(OutputStream out) throws IOException, InvalidRangeException { long size = writeBytes(out, NcStream.MAGIC_START); size += sendHeader(out); for (Variable v : ncfile.getVariables()) { NcStreamCompression compress; String compType = v.findAttributeString(CDM.COMPRESS, null); if (compType != null) { if (compType.equalsIgnoreCase(CDM.COMPRESS_DEFLATE)) { compress = NcStreamCompression.deflate(); } else { compress = NcStreamCompression.none(); } } else { compress = NcStreamCompression.none(); } long vsize = v.getSize() * v.getElementSize(); if (vsize > maxChunk) { size += copyChunks(out, v, maxChunk, compress); } else { size += sendData(v, v.getShapeAsSection(), out, compress); } } size += writeBytes(out, NcStream.MAGIC_END); return size; }
NcStreamWriter { public long streamAll(OutputStream out) throws IOException, InvalidRangeException { long size = writeBytes(out, NcStream.MAGIC_START); size += sendHeader(out); for (Variable v : ncfile.getVariables()) { NcStreamCompression compress; String compType = v.findAttributeString(CDM.COMPRESS, null); if (compType != null) { if (compType.equalsIgnoreCase(CDM.COMPRESS_DEFLATE)) { compress = NcStreamCompression.deflate(); } else { compress = NcStreamCompression.none(); } } else { compress = NcStreamCompression.none(); } long vsize = v.getSize() * v.getElementSize(); if (vsize > maxChunk) { size += copyChunks(out, v, maxChunk, compress); } else { size += sendData(v, v.getShapeAsSection(), out, compress); } } size += writeBytes(out, NcStream.MAGIC_END); return size; } }
NcStreamWriter { public long streamAll(OutputStream out) throws IOException, InvalidRangeException { long size = writeBytes(out, NcStream.MAGIC_START); size += sendHeader(out); for (Variable v : ncfile.getVariables()) { NcStreamCompression compress; String compType = v.findAttributeString(CDM.COMPRESS, null); if (compType != null) { if (compType.equalsIgnoreCase(CDM.COMPRESS_DEFLATE)) { compress = NcStreamCompression.deflate(); } else { compress = NcStreamCompression.none(); } } else { compress = NcStreamCompression.none(); } long vsize = v.getSize() * v.getElementSize(); if (vsize > maxChunk) { size += copyChunks(out, v, maxChunk, compress); } else { size += sendData(v, v.getShapeAsSection(), out, compress); } } size += writeBytes(out, NcStream.MAGIC_END); return size; } NcStreamWriter(NetcdfFile ncfile, String location); }
NcStreamWriter { public long streamAll(OutputStream out) throws IOException, InvalidRangeException { long size = writeBytes(out, NcStream.MAGIC_START); size += sendHeader(out); for (Variable v : ncfile.getVariables()) { NcStreamCompression compress; String compType = v.findAttributeString(CDM.COMPRESS, null); if (compType != null) { if (compType.equalsIgnoreCase(CDM.COMPRESS_DEFLATE)) { compress = NcStreamCompression.deflate(); } else { compress = NcStreamCompression.none(); } } else { compress = NcStreamCompression.none(); } long vsize = v.getSize() * v.getElementSize(); if (vsize > maxChunk) { size += copyChunks(out, v, maxChunk, compress); } else { size += sendData(v, v.getShapeAsSection(), out, compress); } } size += writeBytes(out, NcStream.MAGIC_END); return size; } NcStreamWriter(NetcdfFile ncfile, String location); long sendStart(OutputStream out); long sendEnd(OutputStream out); long sendHeader(OutputStream out); long sendData(Variable v, Section section, OutputStream out, NcStreamCompression compress); long sendData2(Variable v, Section section, OutputStream out, NcStreamCompression compress); long streamAll(OutputStream out); }
NcStreamWriter { public long streamAll(OutputStream out) throws IOException, InvalidRangeException { long size = writeBytes(out, NcStream.MAGIC_START); size += sendHeader(out); for (Variable v : ncfile.getVariables()) { NcStreamCompression compress; String compType = v.findAttributeString(CDM.COMPRESS, null); if (compType != null) { if (compType.equalsIgnoreCase(CDM.COMPRESS_DEFLATE)) { compress = NcStreamCompression.deflate(); } else { compress = NcStreamCompression.none(); } } else { compress = NcStreamCompression.none(); } long vsize = v.getSize() * v.getElementSize(); if (vsize > maxChunk) { size += copyChunks(out, v, maxChunk, compress); } else { size += sendData(v, v.getShapeAsSection(), out, compress); } } size += writeBytes(out, NcStream.MAGIC_END); return size; } NcStreamWriter(NetcdfFile ncfile, String location); long sendStart(OutputStream out); long sendEnd(OutputStream out); long sendHeader(OutputStream out); long sendData(Variable v, Section section, OutputStream out, NcStreamCompression compress); long sendData2(Variable v, Section section, OutputStream out, NcStreamCompression compress); long streamAll(OutputStream out);  }