Example usage for com.google.common.io FileBackedOutputStream FileBackedOutputStream

List of usage examples for com.google.common.io FileBackedOutputStream FileBackedOutputStream

Introduction

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

Prototype

public FileBackedOutputStream(int fileThreshold, boolean resetOnFinalize) 

Source Link

Document

Creates a new instance that uses the given file threshold, and optionally resets the data when the ByteSource returned by #asByteSource is finalized.

Usage

From source file:eu.interedition.text.xml.XMLParserState.java

XMLParserState(Text source, Text target, XMLParserConfiguration configuration) {
    this.source = source;
    this.target = target;
    this.configuration = configuration;
    this.modules = configuration.getModules();
    this.textBuffer = new FileBackedOutputStream(configuration.getTextBufferSize(), true);
    this.lastChar = (configuration.isRemoveLeadingWhitespace() ? ' ' : 0);
}

From source file:io.squark.nestedjarclassloader.NestedJarURLConnection.java

@Override
public void connect() throws IOException {
    file = jarFileURL.getFile();/*w  w  w  . j av  a 2s.  c  om*/
    if (entryName != null) {
        JarFile jarFile = new JarFile(file);
        InputStream is = jarFile.getInputStream(jarFile.getEntry(entryName));
        int len;
        byte[] b = new byte[2048];
        entryOutputStream = new FileBackedOutputStream((int) Runtime.getRuntime().freeMemory() / 2, true);

        while ((len = is.read(b)) > 0) {
            entryOutputStream.write(b, 0, len);
        }

        is.close();
        if (subEntryName != null) {
            JarInputStream entryInputStream = new JarInputStream(
                    entryOutputStream.asByteSource().openBufferedStream());
            JarEntry subEntry;
            while ((subEntry = entryInputStream.getNextJarEntry()) != null) {
                if (subEntry.getName().equals(subEntryName)) {
                    subEntryOutputStream = new FileBackedOutputStream(
                            (int) Runtime.getRuntime().freeMemory() / 2, true);
                    if (subEntry.isDirectory()) {
                        JarInputStream newEntryInputStream = new JarInputStream(
                                entryOutputStream.asByteSource().openBufferedStream());
                        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(subEntryOutputStream);
                        JarEntry file;
                        while ((file = newEntryInputStream.getNextJarEntry()) != null) {
                            if (file.getName().startsWith(subEntryName)) {
                                Path path;
                                if ((path = Paths.get(file.getName())).getNameCount()
                                        - Paths.get(subEntryName).getNameCount() == 1) {
                                    outputStreamWriter.append(path.getFileName().toString()).append('\n');
                                }
                            }
                        }
                        outputStreamWriter.close();
                        newEntryInputStream.close();
                    } else {
                        b = new byte[2048];
                        while ((len = entryInputStream.read(b)) > 0) {
                            subEntryOutputStream.write(b, 0, len);
                        }
                        break;
                    }
                }
            }
            entryInputStream.close();
            entryOutputStream.reset();
            entryOutputStream.close();
            entryOutputStream = null;
        }
    }
    connected = true;
}

From source file:eu.interedition.text.util.AbstractTextRepository.java

protected FileBackedOutputStream createBuffer() {
    return new FileBackedOutputStream(memoryBufferThreshold, true);
}

From source file:eu.interedition.text.Text.java

private static FileBackedOutputStream createBuffer() {
    return new FileBackedOutputStream(MEMORY_BUFFER_THRESHOLD, true);
}

From source file:eu.interedition.text.xml.XMLTransformer.java

void start() {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Start of document");
    }/*from w w  w  .ja v a2  s.  c  o m*/

    elementContext.clear();
    inclusionContext.clear();
    spacePreservationContext.clear();
    nodePath.clear();

    textBuffer = new FileBackedOutputStream(configuration.getTextBufferSize(), true);
    textStartOffset = -1;
    lastChar = (configuration.isRemoveLeadingWhitespace() ? ' ' : 0);

    sourceOffset = 0;
    textOffset = 0;

    sourceOffsetRange = TextRange.NULL;
    textOffsetRange = TextRange.NULL;

    this.nodePath.push(0);
    for (XMLTransformerModule m : modules) {
        m.start(this);
    }
}

From source file:com.hpe.caf.worker.datastore.cs.StorageServiceDataStore.java

@Override
public String store(InputStream inputStream, String partialReference) throws DataStoreException {
    try (FileBackedOutputStream fileBackedOutputStream = new FileBackedOutputStream(FILE_THRESHOLD, true)) {
        try {//  w ww . j av  a  2s  .c  o m
            ByteStreams.copy(inputStream, fileBackedOutputStream);
            return store(fileBackedOutputStream.asByteSource(), partialReference);
        } finally {
            fileBackedOutputStream.reset();
        }
    } catch (IOException ex) {
        errors.incrementAndGet();
        throw new DataStoreException("Could not store input stream.", ex);
    }
}