Example usage for com.google.common.io Files toString

List of usage examples for com.google.common.io Files toString

Introduction

In this page you can find the example usage for com.google.common.io Files toString.

Prototype

public static String toString(File file, Charset charset) throws IOException 

Source Link

Usage

From source file:eu.numberfour.n4js.antlr.AntlrGeneratorWithCustomKeywordLogic.java

private void massageGrammar(String absoluteParserFileName, String encoding) {
    try {// ww  w .  j a v a  2 s. c o  m
        String javaFile = absoluteParserFileName.replaceAll("\\.g$", getParserFileNameSuffix());
        String content = Files.toString(new File(javaFile), Charset.forName(encoding));
        String normalizedContent = content.replace("\r\n", "\n");

        String newContent = fixIdentifierAsKeywordWithEOLAwareness(normalizedContent);

        if (normalizedContent.equals(newContent)) {
            log.warn("Replacement not found in " + javaFile);
            // throw new IllegalStateException("Replacement not found in " + javaFile);
        }
        if (!content.equals(newContent)) {
            Files.write(newContent, new File(javaFile), Charset.forName(encoding));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:datamine.mojo.storage.TableInterfaceContentPrinterGenerationMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    validateArguments();/*from w w  w. j a va 2s  .  co  m*/

    InterfaceContentPrinterGenerator generator = new InterfaceContentPrinterGenerator(
            outputDirectory.getAbsolutePath(), packageName, interfacePackageName);

    try {
        // generate the java source codes
        Schema schema = new JsonSchemaConvertor().apply(Files.toString(schemaPath, Charsets.UTF_8));
        schema.accept(generator);
        generator.generate();
    } catch (IOException e) {
        throw new MojoExecutionException("Error generating Java interfaces for table conversion!", e);
    }
}

From source file:com.android.build.gradle.integration.instant.InstantRunTestUtils.java

@NonNull
public static InstantRunBuildInfo loadContext(@NonNull InstantRun instantRunModel) throws Exception {
    InstantRunBuildInfo context = InstantRunBuildInfo
            .get(Files.toString(instantRunModel.getInfoFile(), Charsets.UTF_8));
    assertNotNull(context);//from  w  ww . j  av  a2 s. c o  m
    return context;
}

From source file:datamine.mojo.storage.recordbuffers.RecordBuffersTableGenerationMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    validateArguments();/*from  ww  w . j av a 2  s.c om*/

    try {
        //0. generate the java source codes
        Schema schema = new JsonSchemaConvertor().apply(Files.toString(schemaPath, Charsets.UTF_8));

        //1. generate wrapper codes
        RecordMetaWrapperGenerator gen = new RecordMetaWrapperGenerator(outputDirectory.getAbsolutePath(),
                packageName, metadataPackageName, interfacePackageName);
        gen.apply(schema);

    } catch (IOException e) {
        throw new MojoExecutionException("Error generating Java classes for table access (by Record Buffers)!",
                e);
    }
}

From source file:org.sonar.plugins.xml.highlighting.XMLHighlighting.java

public XMLHighlighting(XmlFile xmlFile, Charset charset) throws IOException {
    content = Files.toString(xmlFile.getIOFile(), charset);
    delta = xmlFile.getOffsetDelta();/*from  ww  w.  j ava  2  s  .c o m*/

    try {
        highlightXML(new InputStreamReader(new FileInputStream(xmlFile.getIOFile()), charset));
    } catch (XMLStreamException e) {
        LOG.warn("Can't highlight following file : " + xmlFile.getIOFile().getAbsolutePath(), e);
    }
}

From source file:com.jeasyxbrl.conn.Connection.java

public String getConnectionGuava(String filename) { //google guava cache idea
    String contents = null;/*from  w  w w .ja va2s .c o  m*/
    try {
        contents = Files.toString(new File(filename), Charsets.UTF_8);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return contents;
}

From source file:google.registry.tools.ExecuteEppCommand.java

@Override
protected void initMutatingEppToolCommand() throws IOException {
    if (mainParameters.isEmpty()) {
        addXmlCommand(clientId, CharStreams.toString(new InputStreamReader(stdin, UTF_8)));
    } else {/* ww  w. j  a v  a  2  s .c o  m*/
        for (String command : mainParameters) {
            addXmlCommand(clientId, Files.toString(new File(command), UTF_8));
        }
    }
}

From source file:org.sonar.sslr.internal.toolkit.SourceCodeModel.java

public void setSourceCode(File source, Charset charset) {
    this.astNode = configurationModel.getParser().parse(source);

    try {/*from   w  w  w  .j  a v  a2 s  .c o  m*/
        this.sourceCode = Files.toString(source, charset);
    } catch (IOException e) {
        Throwables.propagate(e);
    }
}

From source file:net.minecraftforge.gradle.patcher.TaskProcessJson.java

@TaskAction
public void doTask() throws IOException {
    File inputFile = getReleaseJson();
    File outFile = getInstallerJson();
    File truncatedFile = getUniversalJson();

    String input = Files.toString(inputFile, Constants.CHARSET);

    for (Entry<String, Object> e : replacements.entrySet()) {
        input = input.replace(e.getKey(), Constants.resolveString(e.getValue()));
    }/*from   ww w .j  a v  a 2s . c o  m*/

    // write the replaced output
    Files.write(input.getBytes(Constants.CHARSET), outFile);

    // get just the useful data
    Gson gson = (new GsonBuilder()).setPrettyPrinting().create();
    input = gson.toJson(gson.fromJson(input, Map.class).get("versionInfo"));

    // write the useful truncated data
    Files.write(input.getBytes(Constants.CHARSET), truncatedFile);
}

From source file:ch.raffael.doclets.pegdown.UmlTagRenderer.java

@Override
public void render(Tag tag, StringBuilder target, PegdownDoclet doclet) {
    if (config == null) {
        if (doclet.getOptions().getPlantUmlConfigFile() != null) {
            try {
                config = Collections.singletonList(Files.toString(doclet.getOptions().getPlantUmlConfigFile(),
                        doclet.getOptions().getEncoding()));
            } catch (IOException e) {
                doclet.printError("Error loading PlantUML configuration file "
                        + doclet.getOptions().getPlantUmlConfigFile() + ": " + e.getLocalizedMessage());
            }//from  w ww  .  j  av  a  2 s. c  om
        } else {
            config = Collections.emptyList();
        }
    }
    String packageName;
    if (tag.holder() instanceof ProgramElementDoc) {
        packageName = ((ProgramElementDoc) tag.holder()).containingPackage().name();
    } else if (tag.holder() instanceof PackageDoc) {
        packageName = ((PackageDoc) (tag.holder())).name();
    } else if (tag.holder() instanceof RootDoc) {
        packageName = null;
    } else {
        doclet.printError(tag.position(), "Cannot handle tag for holder " + tag.holder());
        return;
    }
    String source = tag.text().trim();
    int pos = CharMatcher.WHITESPACE.indexIn(source);
    if (pos < 0) {
        doclet.printError(tag.position(), "Invalid @startuml tag: Expected filename and PlantUML source");
        return;
    }
    String fileName = source.substring(0, pos);
    source = "@startuml " + fileName + "\n" + source.substring(pos).trim() + "\n@enduml";
    File outputFile;
    if (packageName == null) {
        outputFile = doclet.getOptions().getDestinationDir();
    } else {
        outputFile = new File(doclet.getOptions().getDestinationDir(),
                packageName.replace(".", File.separator));
    }
    outputFile.mkdirs();
    outputFile = new File(outputFile, fileName.replace("/", File.separator));
    doclet.printNotice("Generating UML diagram " + outputFile);
    // render
    SourceStringReader reader = new SourceStringReader(new Defines(), source, config);
    try {
        reader.generateImage(outputFile);
    } catch (IOException e) {
        doclet.printError(tag.position(),
                "Error generating UML image " + outputFile + ": " + e.getLocalizedMessage());
    }
}