StreamingProductWriter extends AbstractProductWriter { public static void writeProductInSlices(Configuration configuration, ProgressMonitor pm, Product product, Path path, int tileHeight) throws IOException { PathConfiguration output = new PathConfiguration(path, configuration); writeProductInSlices(product, output, StreamingProductPlugin.FORMAT_NAME, tileHeight, pm); } StreamingProductWriter(ProductWriterPlugIn productWriterPlugIn); @Override void writeBandRasterData(Band band, int sourceOffsetX, int sourceOffsetY, int sourceWidth, int sourceHeight, ProductData productData, ProgressMonitor pm); @Override void flush(); @Override void close(); @Override void deleteOutput(); static void writeProductInSlices(Configuration configuration,
                                            ProgressMonitor pm,
                                            Product product,
                                            Path path,
                                            int tileHeight); static void writeProductInSlices(Product product, Object output, String format, int tileHeight, ProgressMonitor pm);  }
@Test public void testDifferentRasterSizes() throws Exception { final int PREFERRED_TILE_SIZE = 8; Product product = new Product("productName", "productWithDifferentBandSizes", 10, 10); product.setPreferredTileSize(PREFERRED_TILE_SIZE, PREFERRED_TILE_SIZE); Band largeBand = new Band("largeBand", ProductData.TYPE_FLOAT32, 10, 10); Band smallBand = new Band("smallBand", ProductData.TYPE_FLOAT32, 3, 3); float[] largeBandData = new float[10 * 10]; float[] smallBandData = new float[3 * 3]; for (int i = 0; i < 10 * 10; i++) { largeBandData[i] = i; } for (int i = 0; i < 3 * 3; i++) { smallBandData[i] = 10000 - i; } largeBand.setData(new ProductData.Float(largeBandData)); smallBand.setData(new ProductData.Float(smallBandData)); product.addBand(largeBand); product.addBand(smallBand); result = new HashMap<>(); StreamingProductWriter.writeProductInSlices(product, new NullWriter(), "NullFormat", PREFERRED_TILE_SIZE, ProgressMonitor.NULL); float[] largeBandData1 = new float[10 * PREFERRED_TILE_SIZE]; float[] largeBandData2 = new float[10 * 2]; for (int i = 0; i < 10 * PREFERRED_TILE_SIZE; i++) { largeBandData1[i] = i; } for (int i = 0; i < 10 * 2; i++) { largeBandData2[i] = 10 * PREFERRED_TILE_SIZE + i; } float[] smallBandData1 = new float[3 * 3]; for (int i = 0; i < 3 * 3; i++) { smallBandData1[i] = 10000 - i; } assertArrayEquals(result.get("largeBand(0)"), largeBandData1, 1E-5F); assertArrayEquals(result.get("largeBand(8)"), largeBandData2, 1E-5F); assertArrayEquals(result.get("smallBand(0)"), smallBandData1, 1E-5F); }
@Test public void testEqualRasterSizes() throws Exception { final int WIDTH = 10; final int HEIGHT = 10; Product product = new Product("productName", "productWithDifferentBandSizes", WIDTH, HEIGHT); product.setPreferredTileSize(4, 8); Band band1 = new Band("band1", ProductData.TYPE_FLOAT32, WIDTH, HEIGHT); Band band2 = new Band("band2", ProductData.TYPE_FLOAT32, WIDTH, HEIGHT); float[] band1Data = new float[WIDTH * HEIGHT]; float[] band2Data = new float[WIDTH * HEIGHT]; for (int i = 0; i < WIDTH * HEIGHT; i++) { band1Data[i] = i; } for (int i = 0; i < WIDTH * HEIGHT; i++) { band2Data[i] = 10000 - i; } band1.setData(new ProductData.Float(band1Data)); band2.setData(new ProductData.Float(band2Data)); product.addBand(band1); product.addBand(band2); result = new HashMap<>(); StreamingProductWriter.writeProductInSlices(product, new NullWriter(), "NullFormat", 10, ProgressMonitor.NULL); }