@Override protected Product doInBackground(com.bc.ceres.core.ProgressMonitor pm) throws Exception { final TargetProductSelectorModel model = getTargetProductSelector().getModel(); pm.beginTask("Writing...", model.isOpenInAppSelected() ? 100 : 95); ProgressMonitorList.instance().add(pm); // NESTMOD saveTime = 0L; Product product = null; try { // free cache // NESTMOD JAI.getDefaultInstance().getTileCache().flush(); System.gc(); executeStartTime = Calendar.getInstance().getTime(); long t0 = System.currentTimeMillis(); Operator operator = null; if (targetProduct.getProductReader() instanceof OperatorProductReader) { final OperatorProductReader opReader = (OperatorProductReader) targetProduct.getProductReader(); if (opReader.getOperatorContext().getOperator() instanceof Output) { operator = opReader.getOperatorContext().getOperator(); } } if (operator == null) { WriteOp writeOp = new WriteOp(targetProduct, model.getProductFile(), model.getFormatName()); writeOp.setDeleteOutputOnFailure(true); writeOp.setWriteEntireTileRows(true); writeOp.setClearCacheAfterRowWrite(false); operator = writeOp; } final OperatorExecutor executor = OperatorExecutor.create(operator); executor.execute(SubProgressMonitor.create(pm, 95)); saveTime = System.currentTimeMillis() - t0; File targetFile = model.getProductFile(); if (model.isOpenInAppSelected() && targetFile.exists()) { product = ProductIO.readProduct(targetFile); if (product == null) { product = targetProduct; // todo - check - this cannot be ok!!! (nf) } pm.worked(5); } } finally { // free cache JAI.getDefaultInstance().getTileCache().flush(); System.gc(); pm.done(); ProgressMonitorList.instance().remove(pm); // NESTMOD if (product != targetProduct) { targetProduct.dispose(); } } return product; }
private static void validateInputProduct( final Parameter parameter, final InputProductValidator validator) { final File file = (File) parameter.getValue(); if (file == null || "".equals(file.getPath().trim())) { return; } String msg = null; if (file.exists()) { Product product = null; try { product = ProductIO.readProduct(file); if (product != null) { if (validator != null) { final boolean valid = validator.validate(product); if (!valid) { msg = validator.getErrorMessage(); if (msg == null) { msg = "Unknown error."; } } } } else { msg = "Unknown product file format."; } } catch (IOException e) { msg = e.getMessage(); } finally { if (product != null) { product.dispose(); } } } else { msg = "File '" + file.getPath() + "' does not exists."; } if (msg != null) { JOptionPane.showMessageDialog( parameter.getEditor().getEditorComponent(), "Invalid input product file:\n" + msg, "Invalid Input Product", JOptionPane.ERROR_MESSAGE); Debug.trace(msg); } }