Sha256: 9906070a86d1163a72bc75ddc909519a69f9b225fe2533db2e3668b288542ca9

Contents?: true

Size: 1.97 KB

Versions: 39

Compression:

Stored size: 1.97 KB

Contents

package org.embulk.spi.util;

import java.util.Iterator;
import java.util.NoSuchElementException;

import org.embulk.spi.Exec;
import org.embulk.spi.FileInput;
import org.embulk.spi.Buffer;
import org.embulk.spi.time.Timestamp;
import org.embulk.spi.time.TimestampFormatter;
import org.joda.time.DateTimeZone;

public class Inputs
{
    private static abstract class AbstractPollIterator <E>
            implements Iterator<E>
    {
        private E next;

        protected abstract E poll();

        @Override
        public boolean hasNext()
        {
            if (next != null) {
                return true;
            } else {
                next = poll();
                return next != null;
            }
        }

        @Override
        public E next()
        {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            E l = next;
            next = null;
            return l;
        }

        @Override
        public void remove()
        {
            throw new UnsupportedOperationException();
        }
    }

    public static Iterable<Buffer> each(final FileInput input)
    {
        return new Iterable<Buffer>() {
            public Iterator<Buffer> iterator()
            {
                return new AbstractPollIterator<Buffer>() {
                    public Buffer poll()
                    {
                        return input.poll();
                    }
                };
            }
        };
    }

    public static String formatPath(String pathFormat)
    {
        Timestamp timestamp = Exec.session().getTransactionTime();
        DateTimeZone timezone = Exec.session().getTransactionTimeZone();
        // newTimestampFormatter (eventually calls org.jruby.util.RubyDateFormat.<init> doesn't throw exceptions
        TimestampFormatter formatter = Exec.session().newTimestampFormatter(pathFormat, timezone);
        return formatter.format(timestamp);  // TimestampFormatter.format doesn't throw exceptions
    }
}

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
embulk-0.6.15 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.14 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.13 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.12 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.11 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.10 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.9 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.8 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.7 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.6 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.5 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.4 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.3 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.2 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.1 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.6.0 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.5.5 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.5.4 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.5.3 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java
embulk-0.5.2 embulk-core/src/main/java/org/embulk/spi/util/Inputs.java