Example usage for org.apache.commons.io IOUtils toCharArray

List of usage examples for org.apache.commons.io IOUtils toCharArray

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils toCharArray.

Prototype

public static char[] toCharArray(Reader input) throws IOException 

Source Link

Document

Get the contents of a Reader as a character array.

Usage

From source file:com.aestasit.markdown.Markdown.java

public static RootNode toAst(final InputStream stream) throws IOException {
    return toAst(IOUtils.toCharArray(stream));
}

From source file:com.aestasit.markdown.Markdown.java

public static RootNode toAst(final InputStream stream, final int options) throws IOException {
    return toAst(IOUtils.toCharArray(stream), options);
}

From source file:com.jsuper.compiler.parser.InputSource.java

private char[] readFile(File file) throws IOException {
    char[] result = null;

    InputStream input = null;/* w  w  w. j a v  a2 s.co m*/
    try {
        input = new BufferedInputStream(new FileInputStream(file));
        result = IOUtils.toCharArray(input);
    } finally {
        IOUtils.closeQuietly(input);
    }

    return result;
}

From source file:com.opensearchserver.extractor.parser.Markdown.java

@Override
protected void parseContent(InputStream inputStream, String extension, String mimeType) throws Exception {
    parseContent(IOUtils.toCharArray(inputStream));
}

From source file:com.blackducksoftware.ohcount4j.SourceFile.java

private char[] prepareContent(int maxLength) throws IOException {
    if (!contentFromFile) {
        // we got content from String buffer which already initialized the content, return it
        return content;
    }/*from w ww . j av  a  2 s  .  c  om*/
    // Lazy load to avoid reading until required
    if (content == null) {
        if (maxLength == -1) {
            // read completely
            content = IOUtils.toCharArray(reader);
        } else {
            char[] buffer = new char[maxLength];
            int readLen = IOUtils.read(reader, buffer, 0, maxLength);
            // we don't know how much will we read, now copy the read length to contents
            content = new char[readLen];
            System.arraycopy(buffer, 0, content, 0, readLen);
        }
    } else if (maxLength == -1 || content.length < maxLength) {
        /*
         * When maxLength is -1
         * content is not null i.e. we did read something, and maxLength is -1 so read remaining.
         */
        int maxRemainingToRead = maxLength == -1 ? maxLength : (maxLength - content.length);
        readContentWithSpecifiedRemainingLength(maxRemainingToRead);
    }
    return content;
}

From source file:at.ac.tuwien.ifs.lupu.LangDetFilterFactory.java

public static synchronized void loadData() throws LangDetectException {
    LOG.log(Level.ALL, "in loadData");
    if (loaded) {
        return;/*  w ww. java 2  s  .c  om*/
    }
    loaded = true;
    List<String> profileData = new ArrayList<>();
    Charset encoding = Charset.forName("UTF-8");
    for (String language : profileLanguages) {
        LOG.log(Level.ALL, "langdetect-profiles/{0}", language);
        ClassLoader loader = Thread.currentThread().getContextClassLoader();

        InputStream stream = loader.getResourceAsStream("langdetect-profiles/" + language);

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, encoding))) {
            profileData.add(new String(IOUtils.toCharArray(reader)));
        } catch (IOException ex) {
            Logger.getLogger(LangDetFilterFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    DetectorFactory.loadProfile(profileData);
    DetectorFactory.setSeed(0);
}

From source file:de.adorsys.forge.plugin.slf4j.Slf4jPlugin.java

private void installJbossAs() throws IOException {
    InputStream is = Slf4jPlugin.class.getResourceAsStream("/templates/MANIFEST.MF");
    ResourceFacet resource = project.getFacet(ResourceFacet.class);
    resource.createResource(IOUtils.toCharArray(is), "/META-INF/MANIFEST.MF");

    Slf4jFacet slf4jFacet = project.getFacet(Slf4jFacet.class);
    slf4jFacet.setSlf4JProvided();/*from   w ww .j  ava2 s.  c  om*/
}

From source file:com.blackducksoftware.ohcount4j.SourceFile.java

private void readContentWithSpecifiedRemainingLength(int remainingLength) throws IOException {
    char[] readRemaining;
    int readLen;//from   w w w . ja  va2s . c o m
    if (remainingLength == -1) {
        readRemaining = IOUtils.toCharArray(reader);
        readLen = readRemaining.length;
    } else {
        // int maxRemainingToRead = maxLength - content.length;
        readRemaining = new char[remainingLength];
        // we don't know how much will we read, now copy the read length to contents
        readLen = IOUtils.read(reader, readRemaining, 0, remainingLength);
    }
    if (readLen != 0) {
        char[] newContents = new char[content.length + readLen];
        System.arraycopy(content, 0, newContents, 0, content.length);
        System.arraycopy(readRemaining, 0, newContents, content.length, readLen);
        content = newContents;
    }
}

From source file:com.amalto.core.storage.hibernate.UpdateReportTypeMapping.java

private String getItemsXml(Wrapper data) {
    String itemsXml = null;/*w w w.j  a  v  a2 s  .c  o  m*/
    Object value = data.get("x_items_xml"); //$NON-NLS-1$
    if (value != null) {
        if (isUsingClob(data)) {
            try {
                Reader characterStream = ((Clob) value).getCharacterStream();
                itemsXml = new String(IOUtils.toCharArray(characterStream));
            } catch (Exception e) {
                throw new RuntimeException("Unexpected read from clob exception", e); //$NON-NLS-1$
            }
        } else {
            itemsXml = (String) value;
        }
    }
    return itemsXml;
}

From source file:com.amalto.core.storage.hibernate.TypeMapping.java

private static Object _deserializeValue(Object value, FieldMetadata sourceField, FieldMetadata targetField) {
    if (targetField == null) {
        return value;
    }//w ww.  j  a v a 2  s. c o m
    if (!targetField.isMany()) {
        Boolean targetZipped = targetField.<Boolean>getData(MetadataRepository.DATA_ZIPPED);
        Boolean sourceZipped = sourceField.<Boolean>getData(MetadataRepository.DATA_ZIPPED);
        if (Boolean.TRUE.equals(sourceZipped) && targetZipped == null) {
            try {
                ByteArrayInputStream bis = new ByteArrayInputStream(String.valueOf(value).getBytes("UTF-8")); //$NON-NLS-1$
                ZipInputStream zis = new ZipInputStream(new Base64InputStream(bis));
                byte[] buffer = new byte[1024];
                int read;
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                while (zis.getNextEntry() != null) {
                    while ((read = zis.read(buffer, 0, buffer.length)) > -1) {
                        bos.write(buffer, 0, read);
                    }
                }
                return new String(bos.toByteArray(), "UTF-8"); //$NON-NLS-1$
            } catch (IOException e) {
                throw new RuntimeException("Unexpected deflate exception", e); //$NON-NLS-1$
            }
        }
        String targetSQLType = sourceField.getType().getData(TypeMapping.SQL_TYPE);
        if (value != null && targetSQLType != null && SQL_TYPE_CLOB.equals(targetSQLType)) {
            try {
                Reader characterStream = ((Clob) value).getCharacterStream();
                return new String(IOUtils.toCharArray(characterStream)); // No need to close (Hibernate seems to
                                                                         // handle this).
            } catch (Exception e) {
                throw new RuntimeException("Unexpected read from clob exception", e); //$NON-NLS-1$
            }
        }
    }
    return value;
}