public ExporterService() { this(new ExporterFactoryLoader(new ExporterContext())); }
/** * Create an exporter that is able to export the given output format. * * @param file * the file to which specification items are written * @param format * the output format * @param charset * the character set used for exporting * @param newline * the newline format * @param itemStream * the items to export * @return an exporter instance */ public Exporter createExporter(final Path file, final String format, final Charset charset, final Newline newline, final Stream<SpecificationItem> itemStream) { if (!supportsFormat(format)) { throw new ExporterException("Output format '" + format + "' not supported for export"); } final Writer writer = createWriter(file, charset); return createExporter(writer, itemStream, newline); }
@Override // [impl->dsn~conversion.reqm2-export~1] public void runExport() { try { writeOutput(); } catch (final XMLStreamException e) { throw new ExporterException("Error exporting to specobject format", e); } finally { closeXmlWriter(); } }
/** * Export the given {@link LinkedSpecificationItem} in the given output * format to a file * * @param itemStream * {@link SpecificationItem} to export * @param outputFile * path to which the export is written * @param settings * exporter settings */ public void exportToPath(final Stream<SpecificationItem> itemStream, final Path outputFile, final ExportSettings settings) { final ExporterFactory factory = this.factoryLoader .getExporterFactory(settings.getOutputFormat()); factory.createExporter(outputFile, settings.getOutputFormat(), StandardCharsets.UTF_8, settings.getNewline(), itemStream).runExport(); } }
private Writer createFileWriter(final Path file, final Charset charset) { try { return Files.newBufferedWriter(file, charset); } catch (final IOException e) { throw new ExporterException("Error creating writer for file " + file, e); } }
@Override public void exportToPath(final List<SpecificationItem> items, final Path path, final ExportSettings settings) { new ExporterService().exportToPath(items.stream(), path, settings); }
private boolean validateConvertCommand() { boolean ok = false; final String format = this.arguments.getOutputFormat(); if (format != null && !new ExporterFactoryLoader(null).isFormatSupported(format)) { this.error = "export format '" + format + "' is not supported."; } else { ok = true; } return ok; }
private Writer createWriter(final Path file, final Charset charset) { if (file == null) { LOG.finest(() -> "Creating exporter for STDOUT using charset " + charset); return new OutputStreamWriter(getStdOutStream(), charset); } LOG.finest(() -> "Creating exporter for file " + file + " using charset " + charset); return createFileWriter(file, charset); }
/** * Determines if the requested format is supported * * @param format * the requested exporter format * @return <code>true</code> if the format is supported */ public boolean isFormatSupported(final String format) { return !getMatchingFactories(format).isEmpty(); } }
/** * Create an exporter that is able to export the given output format. * * @param file * the file to which specification items are written * @param format * the output format * @param charset * the character set used for exporting * @param newline * the newline format * @param itemStream * the items to export * @return an exporter instance */ public Exporter createExporter(final Path file, final String format, final Charset charset, final Newline newline, final Stream<SpecificationItem> itemStream) { if (!supportsFormat(format)) { throw new ExporterException("Output format '" + format + "' not supported for export"); } final Writer writer = createWriter(file, charset); return createExporter(writer, itemStream, newline); }
/** * Export the given {@link LinkedSpecificationItem} in the given output * format to a file * * @param itemStream * {@link SpecificationItem} to export * @param outputFile * path to which the export is written * @param settings * exporter settings */ public void exportToPath(final Stream<SpecificationItem> itemStream, final Path outputFile, final ExportSettings settings) { final ExporterFactory factory = this.factoryLoader .getExporterFactory(settings.getOutputFormat()); factory.createExporter(outputFile, settings.getOutputFormat(), StandardCharsets.UTF_8, settings.getNewline(), itemStream).runExport(); } }
private Writer createFileWriter(final Path file, final Charset charset) { try { return Files.newBufferedWriter(file, charset); } catch (final IOException e) { throw new ExporterException("Error creating writer for file " + file, e); } }
public ExporterService() { this(new ExporterFactoryLoader(new ExporterContext())); }
@Override public void exportToPath(final List<SpecificationItem> items, final Path path, final ExportSettings settings) { new ExporterService().exportToPath(items.stream(), path, settings); }
private boolean validateConvertCommand() { boolean ok = false; final String format = this.arguments.getOutputFormat(); if (format != null && !new ExporterFactoryLoader(null).isFormatSupported(format)) { this.error = "export format '" + format + "' is not supported."; } else { ok = true; } return ok; }
private Writer createWriter(final Path file, final Charset charset) { if (file == null) { LOG.finest(() -> "Creating exporter for STDOUT using charset " + charset); return new OutputStreamWriter(getStdOutStream(), charset); } LOG.finest(() -> "Creating exporter for file " + file + " using charset " + charset); return createFileWriter(file, charset); }
/** * Determines if the requested format is supported * * @param format * the requested exporter format * @return <code>true</code> if the format is supported */ public boolean isFormatSupported(final String format) { return !getMatchingFactories(format).isEmpty(); } }
private XMLStreamWriter createXmlWriter(final Writer writer) { XMLStreamWriter xmlWriter; try { xmlWriter = this.xmlOutputFactory.createXMLStreamWriter(writer); } catch (final XMLStreamException e) { throw new ExporterException("Error creating xml stream writer for writer " + writer, e); } return xmlWriter; } }
private XMLStreamWriter createXmlWriter(final Writer writer) { XMLStreamWriter xmlWriter; try { xmlWriter = this.xmlOutputFactory.createXMLStreamWriter(writer); } catch (final XMLStreamException e) { throw new ExporterException("Error creating xml stream writer for writer " + writer, e); } return xmlWriter; } }
private static PrintStream createPrintStream(final OutputStream stream, final Charset charset) { try { return new PrintStream(stream, false, charset.name()); } catch (final UnsupportedEncodingException e) { throw new ExporterException("Error creating print stream for charset " + charset, e); } }