@Test public void testSaveToFile() throws Exception { final int numberOfRows = 5; final int numberOfColumns = 6; final IGridPaths iGridPaths = new IGridPaths(numberOfRows, numberOfColumns); for (int row = 2; row < 4; row++) { for (int column = 1; column < 4; column++) { iGridPaths.addImage(new File("r" + row + "c" + column + ".txt"), row, column); } } validateSave(iGridPaths, numberOfRows, numberOfColumns); }
public File saveToFile(final File parentDirectory, final Double z, final File emptyImage) throws IOException { if (! parentDirectory.exists()) { if (! parentDirectory.mkdirs()) { throw new IOException("failed to create " + parentDirectory.getAbsolutePath()); } } if (! parentDirectory.canWrite()) { throw new IOException("not allowed to write to " + parentDirectory.getAbsolutePath()); } final File file = new File(parentDirectory, z + ".iGrid"); final String header = "Columns: " + numberOfColumns + "\nRows: " + numberOfRows + "\n"; final String emptyImagePath = emptyImage.getAbsolutePath(); try (final BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charset.forName("US-ASCII"))){ writer.write(header); for (final String imagePath : pathList) { if (imagePath == null) { writer.write(emptyImagePath); } else { writer.write(imagePath); } writer.newLine(); } for (int i = pathList.size(); i < numberOfPaths; i++) { writer.write(emptyImagePath); writer.newLine(); } } LOG.info("saveToFile: exit, added {} paths to {}", numberOfPaths, file.getAbsolutePath()); return file; }
IGridPaths { public File saveToFile(final File parentDirectory, final Double z, final File emptyImage) throws IOException { if (! parentDirectory.exists()) { if (! parentDirectory.mkdirs()) { throw new IOException("failed to create " + parentDirectory.getAbsolutePath()); } } if (! parentDirectory.canWrite()) { throw new IOException("not allowed to write to " + parentDirectory.getAbsolutePath()); } final File file = new File(parentDirectory, z + ".iGrid"); final String header = "Columns: " + numberOfColumns + "\nRows: " + numberOfRows + "\n"; final String emptyImagePath = emptyImage.getAbsolutePath(); try (final BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charset.forName("US-ASCII"))){ writer.write(header); for (final String imagePath : pathList) { if (imagePath == null) { writer.write(emptyImagePath); } else { writer.write(imagePath); } writer.newLine(); } for (int i = pathList.size(); i < numberOfPaths; i++) { writer.write(emptyImagePath); writer.newLine(); } } LOG.info("saveToFile: exit, added {} paths to {}", numberOfPaths, file.getAbsolutePath()); return file; } }
IGridPaths { public File saveToFile(final File parentDirectory, final Double z, final File emptyImage) throws IOException { if (! parentDirectory.exists()) { if (! parentDirectory.mkdirs()) { throw new IOException("failed to create " + parentDirectory.getAbsolutePath()); } } if (! parentDirectory.canWrite()) { throw new IOException("not allowed to write to " + parentDirectory.getAbsolutePath()); } final File file = new File(parentDirectory, z + ".iGrid"); final String header = "Columns: " + numberOfColumns + "\nRows: " + numberOfRows + "\n"; final String emptyImagePath = emptyImage.getAbsolutePath(); try (final BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charset.forName("US-ASCII"))){ writer.write(header); for (final String imagePath : pathList) { if (imagePath == null) { writer.write(emptyImagePath); } else { writer.write(imagePath); } writer.newLine(); } for (int i = pathList.size(); i < numberOfPaths; i++) { writer.write(emptyImagePath); writer.newLine(); } } LOG.info("saveToFile: exit, added {} paths to {}", numberOfPaths, file.getAbsolutePath()); return file; } IGridPaths(final int numberOfRows,
                      final int numberOfColumns); }
IGridPaths { public File saveToFile(final File parentDirectory, final Double z, final File emptyImage) throws IOException { if (! parentDirectory.exists()) { if (! parentDirectory.mkdirs()) { throw new IOException("failed to create " + parentDirectory.getAbsolutePath()); } } if (! parentDirectory.canWrite()) { throw new IOException("not allowed to write to " + parentDirectory.getAbsolutePath()); } final File file = new File(parentDirectory, z + ".iGrid"); final String header = "Columns: " + numberOfColumns + "\nRows: " + numberOfRows + "\n"; final String emptyImagePath = emptyImage.getAbsolutePath(); try (final BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charset.forName("US-ASCII"))){ writer.write(header); for (final String imagePath : pathList) { if (imagePath == null) { writer.write(emptyImagePath); } else { writer.write(imagePath); } writer.newLine(); } for (int i = pathList.size(); i < numberOfPaths; i++) { writer.write(emptyImagePath); writer.newLine(); } } LOG.info("saveToFile: exit, added {} paths to {}", numberOfPaths, file.getAbsolutePath()); return file; } IGridPaths(final int numberOfRows,
                      final int numberOfColumns); void addImage(final File imageFile,
                         final int row,
                         final int column); void addBoxes(final String baseBoxPath,
                         final String pathSuffix,
                         final List<BoxData> boxes); File saveToFile(final File parentDirectory,
                           final Double z,
                           final File emptyImage); }
IGridPaths { public File saveToFile(final File parentDirectory, final Double z, final File emptyImage) throws IOException { if (! parentDirectory.exists()) { if (! parentDirectory.mkdirs()) { throw new IOException("failed to create " + parentDirectory.getAbsolutePath()); } } if (! parentDirectory.canWrite()) { throw new IOException("not allowed to write to " + parentDirectory.getAbsolutePath()); } final File file = new File(parentDirectory, z + ".iGrid"); final String header = "Columns: " + numberOfColumns + "\nRows: " + numberOfRows + "\n"; final String emptyImagePath = emptyImage.getAbsolutePath(); try (final BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charset.forName("US-ASCII"))){ writer.write(header); for (final String imagePath : pathList) { if (imagePath == null) { writer.write(emptyImagePath); } else { writer.write(imagePath); } writer.newLine(); } for (int i = pathList.size(); i < numberOfPaths; i++) { writer.write(emptyImagePath); writer.newLine(); } } LOG.info("saveToFile: exit, added {} paths to {}", numberOfPaths, file.getAbsolutePath()); return file; } IGridPaths(final int numberOfRows,
                      final int numberOfColumns); void addImage(final File imageFile,
                         final int row,
                         final int column); void addBoxes(final String baseBoxPath,
                         final String pathSuffix,
                         final List<BoxData> boxes); File saveToFile(final File parentDirectory,
                           final Double z,
                           final File emptyImage);  }