Example usage for org.apache.hadoop.io Text readString

List of usage examples for org.apache.hadoop.io Text readString

Introduction

In this page you can find the example usage for org.apache.hadoop.io Text readString.

Prototype

public static String readString(DataInput in) throws IOException 

Source Link

Document

Read a UTF8 encoded string from in

Usage

From source file:org.apache.giraph.worker.InputSplitsCallable.java

License:Apache License

/**
 * Talk to ZooKeeper to convert the input split path to the actual
 * InputSplit.//w w w  . j  av  a2s  . c o  m
 *
 * @param inputSplitPath Location in ZK of input split
 * @return instance of InputSplit
 * @throws IOException
 * @throws ClassNotFoundException
 */
protected InputSplit getInputSplit(String inputSplitPath) throws IOException, ClassNotFoundException {
    byte[] splitList;
    try {
        splitList = zooKeeperExt.getData(inputSplitPath, false, null);
    } catch (KeeperException e) {
        throw new IllegalStateException("getInputSplit: KeeperException on " + inputSplitPath, e);
    } catch (InterruptedException e) {
        throw new IllegalStateException("getInputSplit: IllegalStateException on " + inputSplitPath, e);
    }
    context.progress();

    DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(splitList));
    if (useLocality) {
        Text.readString(inputStream); // location data unused here, skip
    }
    InputSplit inputSplit = getInputFormat().readInputSplit(inputStream);

    if (LOG.isInfoEnabled()) {
        LOG.info("getInputSplit: Reserved " + inputSplitPath + " from ZooKeeper and got input split '"
                + inputSplit.toString() + "'");
    }
    return inputSplit;
}

From source file:org.apache.gobblin.metastore.MysqlStateStore.java

License:Apache License

/**
 * An helper function extracted from getAll method originally that has side effects:
 * - Executing queryStatement/*  ww  w  . j  a  v  a 2s . co m*/
 * - Put the result into List<state> object.
 * @throws SQLException
 * @throws Exception
 */
private void execGetAllStatement(PreparedStatement queryStatement, List<T> states)
        throws SQLException, Exception {
    try (ResultSet rs = queryStatement.executeQuery()) {
        while (rs.next()) {
            Blob blob = rs.getBlob(1);
            Text key = new Text();

            try (InputStream is = StreamUtils.isCompressed(blob.getBytes(1, 2))
                    ? new GZIPInputStream(blob.getBinaryStream())
                    : blob.getBinaryStream(); DataInputStream dis = new DataInputStream(is)) {
                // keep deserializing while we have data
                while (dis.available() > 0) {
                    T state = this.stateClass.newInstance();
                    key.readString(dis);
                    state.readFields(dis);
                    states.add(state);
                }
            } catch (EOFException e) {
                // no more data. GZIPInputStream.available() doesn't return 0 until after EOF.
            }
        }
    }
}

From source file:org.apache.gora.filter.FilterList.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    byte opByte = in.readByte();
    operator = Operator.values()[opByte];
    int size = in.readInt();
    if (size > 0) {
        filters = new ArrayList<Filter<K, T>>(size);
        try {//ww  w  .  ja va 2 s .  c  o  m
            for (int i = 0; i < size; i++) {
                @SuppressWarnings("unchecked")
                Class<? extends Filter<K, T>> cls = (Class<? extends Filter<K, T>>) Class
                        .forName(Text.readString(in)).asSubclass(Filter.class);
                Filter<K, T> filter = ReflectionUtils.newInstance(cls);
                filter.readFields(in);
                filters.add(filter);
            }
        } catch (Exception e) {
            throw (IOException) new IOException("Failed filter init").initCause(e);
        }
    }
}

From source file:org.apache.gora.filter.MapFieldValueFilter.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    fieldName = Text.readString(in);
    mapKey = new Utf8(Text.readString(in));
    filterOp = WritableUtils.readEnum(in, FilterOp.class);
    operands.clear();/*from  w  w w . j a va  2  s.co m*/
    int operandsSize = WritableUtils.readVInt(in);
    for (int i = 0; i < operandsSize; i++) {
        Object operand = ObjectWritable.readObject(in, conf);
        if (operand instanceof String) {
            operand = new Utf8((String) operand);
        }
        operands.add(operand);
    }
    filterIfMissing = in.readBoolean();
}

From source file:org.apache.gora.filter.SingleFieldValueFilter.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    fieldName = Text.readString(in);
    filterOp = WritableUtils.readEnum(in, FilterOp.class);
    operands.clear();/*from   www.  j  a v a2  s  .  c  o  m*/
    int operandsSize = WritableUtils.readVInt(in);
    for (int i = 0; i < operandsSize; i++) {
        Object operand = ObjectWritable.readObject(in, conf);
        if (operand instanceof String) {
            operand = new Utf8((String) operand);
        }
        operands.add(operand);
    }
    filterIfMissing = in.readBoolean();
}

From source file:org.apache.gora.mapreduce.StringSerialization.java

License:Apache License

@Override
public Deserializer<String> getDeserializer(Class<String> c) {
    return new Deserializer<String>() {
        private DataInputStream in;

        @Override/*from ww w.  j  a  va2s . c om*/
        public void open(InputStream in) throws IOException {
            this.in = new DataInputStream(in);
        }

        @Override
        public void close() throws IOException {
            this.in.close();
        }

        @Override
        public String deserialize(String t) throws IOException {
            return Text.readString(in);
        }
    };
}

From source file:org.apache.gora.query.impl.QueryBase.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public void readFields(DataInput in) throws IOException {
    String dataStoreClass = Text.readString(in);
    try {//from   w  ww.jav  a  2s. c o m
        dataStore = (DataStoreBase<K, T>) ReflectionUtils
                .newInstance(ClassLoadingUtils.loadClass(dataStoreClass), conf);
        dataStore.readFields(in);
    } catch (ClassNotFoundException ex) {
        throw new IOException(ex);
    }

    boolean[] nullFields = IOUtils.readNullFieldsInfo(in);

    if (!nullFields[0])
        queryString = Text.readString(in);
    if (!nullFields[1])
        fields = IOUtils.readStringArray(in);
    if (!nullFields[2])
        startKey = IOUtils.deserialize(getConf(), in, null, dataStore.getKeyClass());
    if (!nullFields[3])
        endKey = IOUtils.deserialize(getConf(), in, null, dataStore.getKeyClass());
    if (!nullFields[4]) {
        String filterClass = Text.readString(in);
        try {
            filter = (Filter<K, T>) ReflectionUtils.newInstance(ClassLoadingUtils.loadClass(filterClass), conf);
            filter.readFields(in);
        } catch (ClassNotFoundException e) {
            throw new IOException(e);
        }
    }

    startTime = WritableUtils.readVLong(in);
    endTime = WritableUtils.readVLong(in);
    limit = WritableUtils.readVLong(in);
    localFilterEnabled = in.readBoolean();
}

From source file:org.apache.gora.store.impl.DataStoreBase.java

License:Apache License

@SuppressWarnings("unchecked")
public void readFields(DataInput in) {
    try {//  w  w  w .j av a  2  s .co m
        Class<K> keyClass = (Class<K>) ClassLoadingUtils.loadClass(Text.readString(in));
        Class<T> persistentClass = (Class<T>) ClassLoadingUtils.loadClass(Text.readString(in));
        Properties props = WritableUtils.readProperties(in);
        initialize(keyClass, persistentClass, props);
    } catch (ClassNotFoundException ex) {
        LOG.error(ex.getMessage(), ex);
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:org.apache.gora.store.impl.FileBackedDataStoreBase.java

License:Apache License

@Override
public void readFields(DataInput in) {
    try {/*w  ww.ja v a2s  . c  o  m*/
        super.readFields(in);
        boolean[] nullFields = org.apache.gora.util.IOUtils.readNullFieldsInfo(in);
        if (!nullFields[0])
            inputPath = Text.readString(in);
        if (!nullFields[1])
            outputPath = Text.readString(in);
    } catch (IOException ex) {
        LOG.error(ex.getMessage(), ex);
    }
}

From source file:org.apache.gora.util.IOUtils.java

License:Apache License

/** Deserializes the object in the given datainput using
 * available Hadoop serializations./*from  w  ww  .  j ava  2  s.com*/
 * @throws IOException
 * @throws ClassNotFoundException */
@SuppressWarnings("unchecked")
public static <T> T deserialize(Configuration conf, DataInput in, T obj)
        throws IOException, ClassNotFoundException {
    String clazz = Text.readString(in);
    Class<T> c = (Class<T>) ClassLoadingUtils.loadClass(clazz);
    return deserialize(conf, in, obj, c);
}