Sha256: da8d19255f7aecb0f214f332cfdbdc4b433e94cbb3643b7ace9cc6f0fb19cab2

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

package org.embulk.decoder.unzip;

import java.io.IOException;
import java.io.InputStream;

import org.embulk.spi.Buffer;
import org.embulk.spi.BufferAllocator;
import org.embulk.spi.FileInput;
import org.embulk.spi.util.InputStreamFileInput.Provider;


class CommonsCompressFileInput implements FileInput
{
    private final BufferAllocator allocator;
    private final Provider provider;
    private InputStream current;

    public CommonsCompressFileInput(BufferAllocator allocator, Provider provider)
    {
        this.allocator = allocator;
        this.provider = provider;
        this.current = null;
    }

    @Override
    public Buffer poll()
    {
        if (current == null) {
            throw new IllegalStateException("nextFile() must be called before poll()");
        }
        Buffer buffer = allocator.allocate();
        try {
            int n = current.read(buffer.array(), buffer.offset(), buffer.capacity());
            if (n < 0) {
                return null;
            }
            buffer.limit(n);
            Buffer b = buffer;
            buffer = null;
            return b;
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } finally {
            if (buffer != null) {
                buffer.release();
                buffer = null;
            }
        }
    }

    @Override
    public boolean nextFile()
    {
        try {
            // NOTE: DO NOT close current because this stream may
            // be one of a file in an archive. Provider manage it.
            current = provider.openNext();
            return current != null;
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    @Override
    public void close()
    {
        try {
            provider.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
embulk-decoder-unzip-0.1.4 src/main/java/org/embulk/decoder/unzip/CommonsCompressFileInput.java
embulk-decoder-unzip-0.1.3 src/main/java/org/embulk/decoder/unzip/CommonsCompressFileInput.java
embulk-decoder-unzip-0.1.2 src/main/java/org/embulk/decoder/unzip/CommonsCompressFileInput.java