public boolean check() { final Properties oldProps = new Properties(); if (BindingFileSearch.CACHE_LIST.exists()) { try { Reader propIn = Files.newReader(BindingFileSearch.CACHE_LIST, Charset.defaultCharset()); oldProps.load(propIn); } catch (Exception ex) { LOG.debug(ex, ex); } } Map<String, String> oldBindings = Maps.fromProperties(oldProps); Map<String, String> newBindings = Maps.fromProperties(BindingFileSearch.CURRENT_PROPS); if (oldBindings.equals(newBindings)) { LOG.info("Found up-to-date binding class cache: skipping message binding."); return true; } else { MapDifference<String, String> diffBindings = Maps.difference(oldBindings, newBindings); LOG.info("Binding class cache expired (old,new): \n" + diffBindings.entriesDiffering()); try { Files.deleteRecursively(SubDirectory.CLASSCACHE.getFile()); } catch (IOException ex) { LOG.error(ex, ex); } SubDirectory.CLASSCACHE.getFile().mkdir(); return false; } }
private static Map<String, String> getMappingsFromFile(String filename) throws IOException { final Map<String, String> map = Maps.newHashMap(); BufferedReader reader = Files.newReader(new File(filename), CHARSET); String line; while ((line = reader.readLine()) != null) { String[] parts = line.trim().split("\\s"); map.put(parts[0], parts[1]); } reader.close(); return map; }
public static void assertExportedTmxFilesEqual(File testFile, InputStream goalStream) throws IOException, SAXException { try (Reader testReader = Files.newReader(testFile, StandardCharsets.UTF_8); Reader goldReader = new InputStreamReader(goalStream, StandardCharsets.UTF_8)) { Diff diff = new Diff(goldReader, testReader); diff.overrideDifferenceListener( new DifferenceListener() { @Override public void skippedComparison(Node arg0, Node arg1) {} @Override public int differenceFound(Difference d) { Node node = d.getControlNodeDetail().getNode(); if (node.getNodeType() == Node.ATTRIBUTE_NODE && "creationtoolversion".equals(node.getNodeName())) { return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR; } return 0; } }); assertTrue(diff.similar()); } }
private static TwillSpecification loadTwillSpec(File specFile) throws IOException { try (Reader reader = Files.newReader(specFile, Charsets.UTF_8)) { return TwillSpecificationAdapter.create().fromJson(reader); } }
public static void main(String[] args) { Settings fullSettings; String settingsJson; Gson gson = new Gson(); String settingsFileName = SETTINGS_FILE; for (int i = 0; i < args.length; ++i) { if (args[i].equals("--config") && ++i < args.length) { settingsFileName = args[i]; } } File debugFile = new File(DEBUG_FILE); try { debugOut = new BufferedWriter(Files.newWriterSupplier(debugFile, Charsets.UTF_8, true).getOutput()); } catch (IOException e1) { System.err.println("WARN: Cannot write to debug file"); } BufferedReader settingsReader; if (settingsFileName.equals("-")) { settingsReader = new BufferedReader(new InputStreamReader(System.in, Charsets.UTF_8)); } else { File settingsFile = new File(settingsFileName); try { settingsReader = Files.newReader(settingsFile, Charsets.UTF_8); } catch (FileNotFoundException e) { System.err.println("ERROR: Can't find settings file (" + settingsFile + ")"); return; } } try { settingsJson = CharStreams.toString(settingsReader); } catch (IOException e) { System.err.println("ERROR: Error while reading settings file"); return; } OuterSettings outerSettings; try { outerSettings = gson.fromJson(settingsJson, OuterSettings.class); } catch (JsonSyntaxException e) { System.err.println("ERROR: Settings file is malformed!"); return; } fullSettings = outerSettings.getSettings(); dumperEngine = fullSettings.getDumperEngine(); sourceEngine = fullSettings.getSourceEngine(); if (dumperEngine == null) dumperEngine = "DumperJSON"; if (sourceEngine == null) sourceEngine = "YotsubaJSON"; for (String boardName : fullSettings.getBoardSettings().keySet()) { if ("default".equals(boardName)) continue; try { spawnBoard(boardName, fullSettings); } catch (BoardInitException e) { System.err.println("ERROR: Error initializing dumper for /" + boardName + "/:"); System.err.println(" " + e.getMessage()); } } }