/** required flags: model-dir input-file output-file */ public static void main(String[] args) throws Exception { final FNModelOptions options = new FNModelOptions(args); final File inputFile = new File(options.inputFile.get()); final File outputFile = new File(options.outputFile.get()); final String modelDirectory = options.modelDirectory.get(); final int numThreads = options.numThreads.present() ? options.numThreads.get() : 1; final Semafor semafor = getSemaforInstance(modelDirectory); semafor.runParser( Files.newReaderSupplier(inputFile, Charsets.UTF_8), Files.newWriterSupplier(outputFile, Charsets.UTF_8), numThreads); }
private List<ServiceDescriptor> getServiceInventory(SlotStatus slotStatus) { Assignment assignment = slotStatus.getAssignment(); if (assignment == null) { return null; } String config = assignment.getConfig(); File cacheFile = getCacheFile(config); if (cacheFile.canRead()) { try { String json = CharStreams.toString(Files.newReaderSupplier(cacheFile, Charsets.UTF_8)); List<ServiceDescriptor> descriptors = descriptorsJsonCodec.fromJson(json); invalidServiceInventory.remove(config); return descriptors; } catch (Exception ignored) { // delete the bad cache file cacheFile.delete(); } } InputSupplier<? extends InputStream> configFile = ConfigUtils.newConfigEntrySupplier(repository, config, "airship-service-inventory.json"); if (configFile == null) { return null; } try { String json; try { json = CharStreams.toString(CharStreams.newReaderSupplier(configFile, Charsets.UTF_8)); } catch (FileNotFoundException e) { // no service inventory in the config, so replace with json null so caching works json = "null"; } invalidServiceInventory.remove(config); // cache json cacheFile.getParentFile().mkdirs(); Files.write(json, cacheFile, Charsets.UTF_8); List<ServiceDescriptor> descriptors = descriptorsJsonCodec.fromJson(json); return descriptors; } catch (Exception e) { if (invalidServiceInventory.add(config)) { log.error(e, "Unable to read service inventory for %s" + config); } } return null; }
private static Arguments decodeArgs() throws IOException { return ArgumentsCodec.decode( Files.newReaderSupplier(new File(Constants.Files.ARGUMENTS), Charsets.UTF_8)); }