Example usage for org.apache.commons.io Charsets UTF_8

List of usage examples for org.apache.commons.io Charsets UTF_8

Introduction

In this page you can find the example usage for org.apache.commons.io Charsets UTF_8.

Prototype

Charset UTF_8

To view the source code for org.apache.commons.io Charsets UTF_8.

Click Source Link

Document

Eight-bit Unicode Transformation Format.

Usage

From source file:org.datacleaner.cli.GrouperIT.java

private void checkOutputFileForInconsistencies(final String filePath) {
    try {/*from  ww w . j  a v a 2s.c  om*/
        final List<String> lines = Files.readLines(new File(filePath), Charsets.UTF_8);

        for (int i = 1; i < lines.size(); i++) { // skipping header
            final String[] values = lines.get(i).split(";");
            final int grouperCount = Integer.parseInt(StringUtils.strip(values[0], "\""));
            final String[] idList = values[1].split(",");
            final int expectedCount = EXPECTED_GROUP_LENGTHS[i - 1];

            if (grouperCount != idList.length || grouperCount != expectedCount) {
                fail(String.format("Size inconsistency at line: %d (%d != %d || %d != %d)", i, grouperCount,
                        idList.length, grouperCount, expectedCount));
            }
        }
    } catch (IOException e) {
        fail(e.getMessage());
    }
}

From source file:org.dederem.common.service.VersionAnalyseService.java

/**
 * Read method for "Packages" file.//from   w w w .  j a  v  a2  s  .c  o m
 *
 * @param input
 *            InputStream on the text file
 * @return The object populated with the content of the file.
 * @throws IOException
 *             I/O error.
 */
public final DebVersion analyzeFile(final String suite, final InputStream input) throws IOException {
    final DebVersion result = new DebVersion();

    final Map<String, StringBuilder> data = new HashMap<>();
    StringBuilder lastData = null; // NOPMD - init

    final BufferedReader reader = new BufferedReader(new InputStreamReader(input, Charsets.UTF_8));
    String line = reader.readLine();
    while (line != null) {
        if (line.isEmpty()) {
            // manage the end of the bloc
            final DebPackageDesc pkgDesc = this.readPackageDesc(data);
            if (pkgDesc != null) {
                // check if file already present in the repository
                final DebPackageDesc local = this.repoService.getPackageInLocalRepo(suite,
                        pkgDesc.getDebPackage());
                if (local == null) {
                    // add the package to package list.
                    result.getPackages().add(pkgDesc);
                } else {
                    if (this.repoService.checkPackageEquality(pkgDesc, local)) {
                        // add the package to package list.
                        result.getPackages().add(local);
                    } else {
                        // add the package to package list.
                        result.getPackages().add(pkgDesc);
                    }
                }
            }
            data.clear();
        } else {
            // manage a new entry in the current bloc
            if (Character.isWhitespace(line.charAt(0))) {
                if (lastData != null) {
                    lastData.append(line);
                }
            } else {
                final String key = StringUtils.substringBefore(line, ":");
                final String value = StringUtils.substringAfter(line, ":");
                lastData = new StringBuilder(value);
                data.put(key, lastData);
            }
        }
        line = reader.readLine();
    }
    result.setSuite(suite);
    return result;
}

From source file:org.dice_research.topicmodeling.io.json.stream.JsonWritingDocumentConsumer.java

public static JsonWritingDocumentConsumer createJsonWritingDocumentConsumer(OutputStream out) {
    Writer writer = null;//from  w  w w  . java 2 s  . c o m
    try {
        writer = new OutputStreamWriter(new BufferedOutputStream(out), Charsets.UTF_8);
        JsonWritingDocumentConsumer consumer = new JsonWritingDocumentConsumer(writer);
        consumer.writeHead();
        return consumer;
    } catch (Exception e) {
        LOGGER.error("Error while trying to write corpus to XML file. Returning null.", e);
        IOUtils.closeQuietly(writer);
    }
    return null;
}

From source file:org.dice_research.topicmodeling.io.json.stream.StreamBasedJsonDocumentSupplier.java

public static StreamBasedJsonDocumentSupplier createReader(File file, boolean useDocumentIdsFromFile) {
    Reader reader;/* w  w w. jav a2 s .  com*/
    try {
        reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8);
    } catch (IOException e) {
        LOGGER.error("Couldn't create FileReader. Returning null.", e);
        return null;
    }
    return createReader(reader, useDocumentIdsFromFile);
}

From source file:org.dice_research.topicmodeling.io.json.stream.StreamBasedJsonDocumentSupplier.java

public static StreamBasedJsonDocumentSupplier createReader(File file, boolean useDocumentIdsFromFile,
        GsonBuilder builder) {//from  ww  w. j a  v a2s . c  o m
    Reader reader;
    try {
        reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8);
    } catch (IOException e) {
        LOGGER.error("Couldn't create FileReader. Returning null.", e);
        return null;
    }
    return createReader(reader, useDocumentIdsFromFile, builder);
}

From source file:org.dice_research.topicmodeling.io.xml.CorpusXmlReader.java

public void readCorpus(InputStream in) {
    this.corpus = new DocumentListCorpus<List<Document>>(new ArrayList<Document>());
    String text;//from w w w .  j av  a  2s .c o m
    try {
        text = IOUtils.toString(in, Charsets.UTF_8);
    } catch (IOException e) {
        LOGGER.error("Couldn't read stream.", e);
        return;
    }
    parser.parse(text);
}

From source file:org.dice_research.topicmodeling.io.xml.CorpusXmlWriter.java

@Override
public void writeCorpus(Corpus corpus, OutputStream out) throws IOException {
    Writer writer = null;//from  ww w .ja va2s  .  co  m
    try {
        writer = new OutputStreamWriter(out, Charsets.UTF_8);
        writer.write(CorpusXmlTagHelper.XML_FILE_HEAD);
        writer.write("<");
        writer.write(CorpusXmlTagHelper.CORPUS_TAG_NAME);
        writer.write(" ");
        writer.write(CorpusXmlTagHelper.NAMESPACE_DECLARATION);
        writer.write(">\n");
        for (Document d : corpus) {
            writeDocument(writer, d);
        }
        writer.write("</");
        writer.write(CorpusXmlTagHelper.CORPUS_TAG_NAME);
        writer.write(">");
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:org.dice_research.topicmodeling.io.xml.XmlWritingDocumentConsumer.java

public static XmlWritingDocumentConsumer createXmlWritingDocumentConsumer(File file) {
    Writer writer = null;/*  www  .  jav  a 2  s.c  o  m*/
    if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();
    }
    try {
        writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), Charsets.UTF_8);
        XmlWritingDocumentConsumer consumer = new XmlWritingDocumentConsumer(writer);
        consumer.writeHead();
        return consumer;
    } catch (Exception e) {
        LOGGER.error("Error while trying to write corpus to XML file. Returning null.", e);
        IOUtils.closeQuietly(writer);
    }
    return null;
}

From source file:org.dragonet.entity.metadata.type.ByteArrayMeta.java

public ByteArrayMeta(String data) {
    this(data.getBytes(Charsets.UTF_8));
}

From source file:org.dspace.app.util.GoogleMetadataTest.java

/**
 * Test to see the priorities work, the PDF should be returned
 * @throws Exception//from   w  w w .  j  a  v  a  2s.  co m
 */
@Test
public void testGetPDFURLDifferentMimeTypes() throws Exception {
    context.turnOffAuthorisationSystem();
    Bundle bundle = ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL");
    Bitstream b = bitstreamService.create(context,
            new ByteArrayInputStream("Bitstream 1".getBytes(Charsets.UTF_8)));
    b.setName(context, "Word");
    b.setFormat(context, bitstreamFormatService.create(context));
    b.getFormat(context).setMIMEType("application/msword");
    bundleService.addBitstream(context, bundle, b);
    Bitstream b2 = bitstreamService.create(context,
            new ByteArrayInputStream("Bitstream 2".getBytes(Charsets.UTF_8)));
    b2.setName(context, "Pdf");
    b2.setFormat(context, bitstreamFormatService.create(context));
    b2.getFormat(context).setMIMEType("application/pdf");
    bundleService.addBitstream(context, bundle, b2);
    Bitstream b3 = bitstreamService.create(context,
            new ByteArrayInputStream("Bitstream 3".getBytes(Charsets.UTF_8)));
    b3.setName(context, "Rtf");
    b3.setFormat(context, bitstreamFormatService.create(context));
    b3.getFormat(context).setMIMEType("text/richtext");
    bundleService.addBitstream(context, bundle, b3);
    context.restoreAuthSystemState();
    context.commit();
    GoogleMetadata gm = new GoogleMetadata(this.context, it);
    String[] urlSplitted = gm.getPDFURL().get(0).split("/");
    assertEquals("Pdf", urlSplitted[urlSplitted.length - 1]);
}