List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:com.wolvereness.overmapped.OverMapped.java
private void process() throws Throwable { validateInput();//ww w . j av a 2 s. c o m final MultiProcessor executor = MultiProcessor.newMultiProcessor(cores - 1, new ThreadFactoryBuilder().setDaemon(true) .setNameFormat(OverMapped.class.getName() + "-processor-%d") .setUncaughtExceptionHandler(this).build()); final Future<?> fileCopy = executor.submit(new Callable<Object>() { @Override public Object call() throws Exception { if (original != null) { if (original.exists()) { original.delete(); } Files.copy(input, original); } return null; } }); final Future<Iterable<?>> mappings = executor.submit(new Callable<Iterable<?>>() { @Override public Iterable<?> call() throws Exception { final Object yaml = new Yaml().load(Files.toString(maps, Charset.forName("UTF8"))); if (yaml instanceof Iterable) return (Iterable<?>) yaml; if (yaml instanceof Map) return ImmutableList.of(yaml); throw new ClassCastException(String.format("%s (%s) implements neither %s nor %s", yaml, yaml == null ? Object.class : yaml.getClass(), Iterable.class, Map.class)); } }); final Map<String, ByteClass> byteClasses = newLinkedHashMap(); final List<Pair<ZipEntry, byte[]>> fileEntries = newArrayList(); readClasses(executor, byteClasses, fileEntries); try { reorderEntries(byteClasses); } catch (final CircularOrderException ex) { final Throwable throwable = new MojoFailureException("Circular class hiearchy detected"); throwable.initCause(ex); throw throwable; } final Multimap<String, String> depends = processDepends(byteClasses); final Multimap<String, String> rdepends = processReverseDepends(depends); final BiMap<String, String> nameMaps = HashBiMap.create(byteClasses.size()); final BiMap<String, String> inverseNameMaps = nameMaps.inverse(); final BiMap<Signature, Signature> signatureMaps = HashBiMap.create(); final BiMap<Signature, Signature> inverseSignatureMaps = signatureMaps.inverse(); final Map<Signature, Integer> flags = newHashMap(); final Remapper inverseMapper = new Remapper() { @Override public String map(final String typeName) { final String name = inverseNameMaps.get(typeName); if (name != null) return name; return typeName; } }; prepareSignatures(byteClasses, rdepends, nameMaps, signatureMaps); final Signature.MutableSignature signature = Signature.newMutableSignature("", "", ""); final Set<String> searchCache = newHashSet(); for (final Object mapping : mappings.get()) { final Map<?, ?> map = (Map<?, ?>) mapping; for (final SubRoutine subRoutine : SubRoutine.SUB_ROUTINES) { try { subRoutine.invoke(this, byteClasses, depends, rdepends, nameMaps, inverseNameMaps, signatureMaps, inverseSignatureMaps, inverseMapper, signature, searchCache, flags, map); } catch (final Exception ex) { final Throwable throwable = new MojoFailureException("Failed to parse mappings in " + mapping); throwable.initCause(ex); throw throwable; } } } try { fileCopy.get(); } catch (final ExecutionException ex) { throw new MojoFailureException(String.format("Could not copy `%s' to `%s'", input, original)); } writeToFile(executor, byteClasses, fileEntries, nameMaps, signatureMaps, flags); executor.shutdown(); final Pair<Thread, Throwable> uncaught = this.uncaught; if (uncaught != null) throw new MojoExecutionException(String.format("Uncaught exception in %s", uncaught.getLeft()), uncaught.getRight()); }
From source file:net.minecraftforge.gradle.tasks.PostDecompileTask.java
private static ContextualPatch findPatch(Collection<File> files, ContextProvider provider) throws Exception { ContextualPatch patch = null;/*from w ww .j a v a 2s.c o m*/ for (File f : files) { patch = ContextualPatch.create(Files.toString(f, Constants.CHARSET), provider); List<PatchReport> errors = patch.patch(true); boolean success = true; for (PatchReport rep : errors) { if (!rep.getStatus().isSuccess()) success = false; } if (success) break; } return patch; }
From source file:com.brighttag.agathon.dao.zerg.ZergDaoModule.java
@Provides @Singleton/*from www.ja v a2s. c om*/ @Named(ZERG_RING_CONFIG_PROPERTY) Map<String, Map<String, String>> provideCassandraRingConfigMap( @Named(ZERG_RING_CONFIG_PROPERTY) String filename, Gson gson) throws IOException { String json = Files.toString(new File(filename), Charsets.UTF_8); return gson.fromJson(json, RING_CONFIG_FILE_TYPE); }
From source file:org.eclipse.andmore.internal.wizards.newproject.ImportedProject.java
@Nullable private String findEclipseProjectName() { File projectFile = new File(mLocation, ".project"); //$NON-NLS-1$ if (projectFile.exists()) { String xml;/* w w w . j a v a 2 s . co m*/ try { xml = Files.toString(projectFile, Charsets.UTF_8); Document doc = DomUtilities.parseDocument(xml, false); if (doc != null) { NodeList names = doc.getElementsByTagName(ATTR_NAME); if (names.getLength() >= 1) { Node nameElement = names.item(0); String name = nameElement.getTextContent().trim(); if (!name.isEmpty()) { return name; } } } } catch (IOException e) { // pass: don't attempt to read project name; must be some sort of unrelated // file with the same name, perhaps from a different editor or IDE } } return null; }
From source file:at.nonblocking.maven.nonsnapshot.NonSnapshotUpdateVersionsMojo.java
private static File getChangeScope(MavenModule mavenModule) { try {// w ww. j a va 2 s .c o m if (Files.toString(mavenModule.getPomFile(), StandardCharsets.UTF_8) .contains("<packaging>pom</packaging>")) { return mavenModule.getPomFile(); } } catch (IOException e) { throw new RuntimeException(e); } return mavenModule.getPomFile().getParentFile(); }
From source file:org.jcruncher.less.LessProcessor.java
private String compile(File input) { try {//from ww w . ja v a2 s.c om String result = null; // long time = System.currentTimeMillis(); // logger.debug("Compiling File: " + "file:" + input.getAbsolutePath()); //result = call(compileFile, new Object[] { "file:" + input.getAbsolutePath(), classLoader }); // logger.debug("The compilation of '" + input + "' took " + (System.currentTimeMillis () - time) + " ms."); String location = input.getAbsolutePath(); String source = Files.toString(input, Charsets.UTF_8); boolean compress = false; result = call(compileFunc, source, location, compress); return result; } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:com.cedarsoft.couchdb.core.DesignDocuments.java
/** * Creates a design document for the given js files (view and map functions) * * @param id the id//from w w w .j ava 2s . c om * @param jsFiles the js files (the view and map functions) * @return the design document * * @throws IOException */ @Nonnull public static DesignDocument createDesignDocument(@Nonnull String id, @Nonnull Iterable<? extends File> jsFiles) throws IOException { @Nonnull Map<String, String> mappingFunctions = new HashMap<>(); @Nonnull Map<String, String> reduceFunctions = new HashMap<>(); for (File jsFile : jsFiles) { String content = Files.toString(jsFile, Charsets.UTF_8); if (content.trim().isEmpty()) { continue; } if (isMappingFile(jsFile.getName())) { String name = getBaseName(jsFile.getName()); mappingFunctions.put(name, content); } else if (isReduceFile(jsFile.getName())) { String name = getBaseName(jsFile.getName()); reduceFunctions.put(name, content); } else { throw new IllegalArgumentException("Invalid file name <" + jsFile.getName() + ">"); } } return bundle(id, mappingFunctions, reduceFunctions); }
From source file:com.netflix.spinnaker.orca.pipelinetemplate.v1schema.converter.PipelineTemplateConverter.java
private String loadTemplateHeader() { try {//from www . j a v a2 s . com return Files.toString(new File(Resources.getResource("pipelineTemplateHeader.txt").toURI()), Charsets.UTF_8); } catch (IOException | URISyntaxException e) { log.error("Could not load pipeline template header resource", e); return "GENERATED BY spinnaker"; } }
From source file:org.erlide.runtime.runtimeinfo.RuntimeInfo.java
private static String readOtpVersion(final String path) { final File file = new File(path + "/OTP_VERSION"); try {// ww w.j a v a 2s . c o m return Files.toString(file, Charsets.US_ASCII).trim(); } catch (final IOException e) { } return null; }
From source file:com.axelor.studio.service.builder.MenuBuilderService.java
/** * Load existing menu file from custom module's resource directory. It * create list of menuItems and update actionMap. * /* w w w.jav a 2 s . c o m*/ * @param menuFile * MenuFile in resource directory. * @throws JAXBException * Exception thrown in parsing xml. * @throws IOException * Exception thrown in saving xml file. */ private void loadFile(File menuFile) throws JAXBException, IOException { if (!menuFile.exists()) { return; } String fileContent = Files.toString(menuFile, Charsets.UTF_8); ObjectViews objectViews = XMLViews.fromXML(fileContent); if (objectViews.getMenus() != null) { menuItems = objectViews.getMenus(); } if (objectViews.getActions() != null) { for (Action action : objectViews.getActions()) { actionMap.put(action.getName(), action); } } }