Example usage for org.apache.commons.io.input ReaderInputStream ReaderInputStream

List of usage examples for org.apache.commons.io.input ReaderInputStream ReaderInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io.input ReaderInputStream ReaderInputStream.

Prototype

public ReaderInputStream(Reader reader, String charsetName) 

Source Link

Document

Construct a new ReaderInputStream with a default input buffer size of 1024 characters.

Usage

From source file:org.obm.push.mail.bean.EmailReader.java

public ReaderInputStream toInputStream() {
    Preconditions.checkState(!toInputStreamLock.getAndSet(true) && !readerActionLock.getAndSet(true),
            "Cannot call toInputStream when any action have been done");
    return new ReaderInputStream(reader, charset.name());
}

From source file:org.roda.core.plugins.plugins.characterization.TikaFullTextPluginUtils.java

public static LinkingIdentifier runTikaFullTextOnFile(ModelService model, File file,
        boolean doFeatureExtraction, boolean doFulltextExtraction) throws NotFoundException, GenericException,
        RequestNotValidException, AuthorizationDeniedException, ValidationException, IOException {

    boolean notify = true; // need to index tika properties...

    if (!file.isDirectory() && (doFeatureExtraction || doFulltextExtraction)) {
        StoragePath storagePath = ModelUtils.getFileStoragePath(file);
        Binary binary = model.getStorage().getBinary(storagePath);

        Metadata metadata = new Metadata();
        InputStream inputStream = null;
        try {/*from www  .  j  av  a 2 s . c om*/
            inputStream = binary.getContent().createInputStream();
            final Reader reader = tika.parse(inputStream, metadata);

            ContentPayload payload = new InputStreamContentPayload(new ProvidesInputStream() {
                @Override
                public InputStream createInputStream() throws IOException {
                    return new ReaderInputStream(reader, RodaConstants.DEFAULT_ENCODING);
                }
            });

            if (doFulltextExtraction) {
                model.createOrUpdateOtherMetadata(file.getAipId(), file.getRepresentationId(), file.getPath(),
                        file.getId(), RodaConstants.TIKA_FILE_SUFFIX_FULLTEXT,
                        RodaConstants.OTHER_METADATA_TYPE_APACHE_TIKA, payload, notify);
            }

        } catch (Exception e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(inputStream);
        }

        try {
            if (doFeatureExtraction && metadata != null && metadata.size() > 0) {
                String metadataAsString = generateMetadataFile(metadata);
                ContentPayload metadataAsPayload = new StringContentPayload(metadataAsString);
                model.createOrUpdateOtherMetadata(file.getAipId(), file.getRepresentationId(), file.getPath(),
                        file.getId(), RodaConstants.TIKA_FILE_SUFFIX_METADATA,
                        RodaConstants.OTHER_METADATA_TYPE_APACHE_TIKA, metadataAsPayload, notify);

                // update PREMIS
                String creatingApplicationName = metadata.get("Application-Name");
                String creatingApplicationVersion = metadata.get("Application-Version");
                String dateCreatedByApplication = metadata.get("Creation-Date");

                if (StringUtils.isNotBlank(creatingApplicationName)
                        || StringUtils.isNotBlank(creatingApplicationVersion)
                        || StringUtils.isNotBlank(dateCreatedByApplication)) {
                    PremisV3Utils.updateCreatingApplicationPreservationMetadata(model, file.getAipId(),
                            file.getRepresentationId(), file.getPath(), file.getId(), creatingApplicationName,
                            creatingApplicationVersion, dateCreatedByApplication, notify);
                }
            }
        } catch (Exception e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }

    return PluginHelper.getLinkingIdentifier(file.getAipId(), file.getRepresentationId(), file.getPath(),
            file.getId(), RodaConstants.PRESERVATION_LINKING_OBJECT_SOURCE);
}