private static Properties parseConfig(InputStream stream) throws IOException { final Properties formatterOptions = readConfigInternal(); formatterOptions.load(stream); return formatterOptions; }
/** * Format the given {@link String} as a Java source file, using the built in code format style. * * @param source the source to format * @return the formatted source code * @throws FormatterException if the source coudn't be formatted */ public static String format(String source) { Properties options = readConfigInternal(); return format(options, source); }
/** * Format the given {@link String} as a Java source file, using the built in code format style. */ public static String format(String source) { Properties options = readConfigInternal(); return format(options, source); }
private static Properties parseConfig(InputStream stream) throws IOException { try { final Properties formatterOptions = readConfigInternal(); formatterOptions.load(stream); return formatterOptions; } finally { Streams.closeQuietly(stream); } }
private static Properties parseXmlConfig(InputStream stream) throws IOException { Properties properties = readConfigInternal(); Properties defaultProperties = FormatterProfileReader.fromEclipseXml(stream).getDefaultProperties(); properties.putAll(defaultProperties); return properties; } }
/** * Format the given Java source {@link File} using the given Eclipse code format properties {@link File}. * * @param prefs the format properties file * @param source the file which contains the source to format * @throws FormatterException if the source coudn't be formatted * @throws IOException When the file cannot be read or written, or the preferences cannot be read. */ public static void format(File prefs, File source) throws IOException { Properties options = readConfig(prefs); if (options == null) options = readConfigInternal(); try (InputStream in = new BufferedInputStream(new FileInputStream(source)); OutputStream out = new BufferedOutputStream(new FileOutputStream(source))) { String content = Streams.toString(in); String formatted = format(options, content); Streams.write(new ByteArrayInputStream(formatted.getBytes()), out); } }
private static Properties parseXmlConfig(InputStream stream) throws IOException { try { Properties properties = readConfigInternal(); Properties defaultProperties = FormatterProfileReader.fromEclipseXml(stream).getDefaultProperties(); properties.putAll(defaultProperties); return properties; } finally { Streams.closeQuietly(stream); } }
/** * Format the given Java source {@link File} using the given Eclipse code format properties {@link File}. * * @throws IOException When the file cannot be read or written, or the preferences cannot be read. */ public static void format(File prefs, File source) throws IOException { Properties options = readConfig(prefs); if (options == null) options = readConfigInternal(); InputStream in = null; OutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(source)); String content = Streams.toString(in); String formatted = format(options, content); out = new BufferedOutputStream(new FileOutputStream(source)); Streams.write(new ByteArrayInputStream(formatted.getBytes()), out); } finally { Streams.closeQuietly(in); Streams.closeQuietly(out); } }