@Override public String get() { final String output; try { if (!isFileReadable(file)) { output = ""; } else { output = new String(readAllBytes(file), charset); } } catch (final IOException e) { return ""; } return output; }
public TestOutputStream() throws IOException { tempFile = IOUtility.createTempFilePath("test", ""); out = newOutputStream(tempFile, WRITE, CREATE, TRUNCATE_EXISTING); }
final Path finalHtmlFile = createTempFilePath("schemacrawler", "html"); final Path baseHtmlFile = createTempFilePath("schemacrawler", "html"); final Path baseSvgFile = createTempFilePath("schemacrawler", "svg"); copy(newBufferedReader(finalHtmlFile, UTF_8), writer);
protected AbstractGraphProcessExecutor(final Path dotFile, final Path outputFile, final GraphOutputFormat graphOutputFormat) throws SchemaCrawlerException { requireNonNull(dotFile, "No DOT file provided"); requireNonNull(outputFile, "No graph output file provided"); requireNonNull(graphOutputFormat, "No graph output format provided"); this.dotFile = dotFile.normalize().toAbsolutePath(); this.outputFile = outputFile.normalize().toAbsolutePath(); this.graphOutputFormat = graphOutputFormat; if (!isFileReadable(this.dotFile)) { throw new SchemaCrawlerException("Cannot read DOT file, " + this.dotFile); } if (!isFileWritable(this.outputFile)) { throw new SchemaCrawlerException("Cannot write output file, " + this.outputFile); } }
public static String readFully(final InputStream stream) { if (stream == null) { return null; } final Reader reader = new InputStreamReader(stream, UTF_8); return readFully(reader); }
private static String htmlHeader() { final StringBuilder styleSheet = new StringBuilder(4096); styleSheet.append(System.lineSeparator()) .append(readResourceFully("/sc.css")).append(System.lineSeparator()) .append(readResourceFully("/sc_output.css")) .append(System.lineSeparator()); final String htmlHeaderTemplate = readResourceFully("/html.header.txt"); final String htmlHeader = String.format(htmlHeaderTemplate, styleSheet); return htmlHeader; }
public static String getFileExtension(final Path file) { if (file == null) { return ""; } else { final String fileName = file.toString(); return getFileExtension(fileName == null? "": fileName); } }
private void printHelpText(final InputResource helpResource) { if (helpResource == null) { return; } try (final Reader helpReader = helpResource.openNewInputReader(UTF_8);) { IOUtility.copy(helpReader, out); out.println(); out.flush(); // Do not close System.out } catch (final IOException e) { LOGGER.log(Level.WARNING, String.format("Could not print help from resource <%s>", helpResource), e); } }
public static String readFully(final InputStream stream) { if (stream == null) { return null; } final Reader reader = new InputStreamReader(stream, UTF_8); return readFully(reader); }
private void showCommandline(final Path outputFile, final List<String> command) { if (!LOGGER.isLoggable(Level.SEVERE)) { return; } // Find name of DOT file in local directory final Path movedDotFile = outputFile.normalize().getParent() .resolve(outputFile.getFileName() + ".dot"); // Print command to run command.remove(command.size() - 1); command.remove(command.size() - 1); command.add(outputFile.toString()); command.add(movedDotFile.toString()); LOGGER.log(Level.SEVERE, String.format("%s%nGenerate your diagram manually, using:%n%s", readResourceFully("/dot.error.txt"), String.join(" ", command))); }
protected AbstractGraphProcessExecutor(final Path dotFile, final Path outputFile, final GraphOutputFormat graphOutputFormat) throws SchemaCrawlerException { requireNonNull(dotFile, "No DOT file provided"); requireNonNull(outputFile, "No graph output file provided"); requireNonNull(graphOutputFormat, "No graph output format provided"); this.dotFile = dotFile.normalize().toAbsolutePath(); this.outputFile = outputFile.normalize().toAbsolutePath(); this.graphOutputFormat = graphOutputFormat; if (!isFileReadable(this.dotFile)) { throw new SchemaCrawlerException("Cannot read DOT file, " + this.dotFile); } if (!isFileWritable(this.outputFile)) { throw new SchemaCrawlerException("Cannot write output file, " + this.outputFile); } }
public static String getFileExtension(final Path file) { if (file == null) { return ""; } else { final String fileName = file.toString(); return getFileExtension(fileName == null? "": fileName); } }
private void printHelpText(final InputResource helpResource) { if (helpResource == null) { return; } try (final Reader helpReader = helpResource.openNewInputReader(UTF_8);) { IOUtility.copy(helpReader, out); out.println(); out.flush(); // Do not close System.out } catch (final IOException e) { LOGGER.log(Level.WARNING, String.format("Could not print help from resource <%s>", helpResource), e); } }
@Override public String get() { final String output; try { if (!isFileReadable(file)) { output = ""; } else { output = new String(readAllBytes(file), charset); } } catch (final IOException e) { return ""; } return output; }
private Path createConfig(final Map<String, String> config) throws IOException { final String prefix = "SchemaCrawler.TestCommandLineConfig"; final Path configFile = IOUtility.createTempFilePath(prefix, "properties"); final Properties configProperties = new Properties(); configProperties.putAll(config); configProperties.store(newBufferedWriter(configFile, UTF_8), prefix); return configFile; }
public static String readResourceFully(final String resource) { return readFully(IOUtility.class.getResourceAsStream(resource)); }
private String makeGraphvizHeader() { final Map<String, String> graphvizAttributes = options .getGraphvizAttributes(); final String graphvizHeaderTemplate = readResourceFully("/dot.header.txt"); final String graphvizHeader = String .format(graphvizHeaderTemplate, makeGraphvizAttributes(graphvizAttributes, "graph"), makeGraphvizAttributes(graphvizAttributes, "node"), makeGraphvizAttributes(graphvizAttributes, "edge")); return graphvizHeader; }
final Path finalHtmlFile = createTempFilePath("schemacrawler", "html"); final Path baseHtmlFile = createTempFilePath("schemacrawler", "html"); final Path baseSvgFile = createTempFilePath("schemacrawler", "svg"); copy(newBufferedReader(finalHtmlFile, UTF_8), writer);
protected AbstractGraphProcessExecutor(final Path dotFile, final Path outputFile, final GraphOutputFormat graphOutputFormat) throws SchemaCrawlerException { requireNonNull(dotFile, "No DOT file provided"); requireNonNull(outputFile, "No graph output file provided"); requireNonNull(graphOutputFormat, "No graph output format provided"); this.dotFile = dotFile.normalize().toAbsolutePath(); this.outputFile = outputFile.normalize().toAbsolutePath(); this.graphOutputFormat = graphOutputFormat; if (!isFileReadable(this.dotFile)) { throw new SchemaCrawlerException("Cannot read DOT file, " + this.dotFile); } if (!isFileWritable(this.outputFile)) { throw new SchemaCrawlerException("Cannot write output file, " + this.outputFile); } }
private ScriptEngine getScriptEngine() throws SchemaCrawlerException { final String scriptFileName = outputOptions.getOutputFormatValue(); if (isBlank(scriptFileName)) { throw new SchemaCrawlerCommandLineException("Please specify a script to execute"); } final String scriptExtension = getFileExtension(scriptFileName); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ScriptEngine scriptEngine; if (isBlank(scriptExtension)) { scriptEngine = scriptEngineManager.getEngineByName("nashorn"); } else { scriptEngine = scriptEngineManager.getEngineByExtension(scriptExtension); } if (scriptEngine == null) { throw new SchemaCrawlerException("Script engine not found"); } logScriptEngineDetails(Level.CONFIG, scriptEngine.getFactory()); return scriptEngine; }