List of usage examples for org.apache.hadoop.io Text readString
public static String readString(DataInput in) throws IOException
From source file:oracle.kv.hadoop.KVInputSplit.java
License:Open Source License
/** * Deserialize the fields of this object from <code>in</code>. * * <p>For efficiency, implementations should attempt to re-use storage in * the existing object where possible.</p> * * @param in <code>DataInput</code> to deseriablize this object from. * @throws IOException//from w ww .j a va 2s. c om */ @Override public void readFields(DataInput in) throws IOException { final int nHelperHosts = in.readInt(); kvHelperHosts = new String[nHelperHosts]; for (int i = 0; i < nHelperHosts; i++) { kvHelperHosts[i] = Text.readString(in); } kvStore = Text.readString(in); kvPart = Integer.parseInt(Text.readString(in)); partitionSets = null; /* If kvPart == 0, then this is a multi-partition split. */ if (kvPart == 0) { int nSets = in.readInt(); if (nSets > 0) { partitionSets = new ArrayList<Set<Integer>>(nSets); while (nSets > 0) { int nPartitions = in.readInt(); final Set<Integer> partitions = new HashSet<Integer>(nPartitions); partitionSets.add(partitions); while (nPartitions > 0) { partitions.add(in.readInt()); nPartitions--; } nSets--; } } } final String dirStr = Text.readString(in); if (dirStr == null || dirStr.equals("")) { direction = Direction.FORWARD; } else { direction = Direction.valueOf(dirStr); } batchSize = in.readInt(); final byte[] pkBytes = readBytes(in); if (pkBytes == null) { parentKey = null; } else { parentKey = Key.fromByteArray(pkBytes); } final byte[] srBytes = readBytes(in); if (srBytes == null) { subRange = null; } else { subRange = KeyRange.fromByteArray(srBytes); } final String depthStr = Text.readString(in); if (depthStr == null || depthStr.equals("")) { depth = Depth.PARENT_AND_DESCENDANTS; } else { depth = Depth.valueOf(depthStr); } final byte[] consBytes = readBytes(in); if (consBytes == null) { consistency = null; } else { consistency = Consistency.fromByteArray(consBytes); } timeout = in.readLong(); final String tuStr = Text.readString(in); if (tuStr == null || tuStr.equals("")) { timeoutUnit = null; } else { timeoutUnit = TimeUnit.valueOf(tuStr); } final int len = in.readInt(); locations = new String[len]; for (int i = 0; i < len; i++) { locations[i] = Text.readString(in); } formatterClassName = Text.readString(in); if (formatterClassName == null || formatterClassName.equals("")) { formatterClassName = null; } kvStoreSecurityFile = Text.readString(in); if (kvStoreSecurityFile == null || kvStoreSecurityFile.equals("")) { kvStoreSecurityFile = null; } }
From source file:oracle.kv.hadoop.table.TableInputSplit.java
License:Open Source License
/** * Deserialize the fields of this object from <code>in</code>. * * <p>For efficiency, implementations should attempt to re-use storage in * the existing object where possible.</p> * * @param in <code>DataInput</code> to deseriablize this object from. * @throws IOException// w w w . j a v a 2 s. c o m */ @Override public void readFields(DataInput in) throws IOException { final int len = in.readInt(); locations = new String[len]; for (int i = 0; i < len; i++) { locations[i] = Text.readString(in); } final int nHelperHosts = in.readInt(); kvHelperHosts = new String[nHelperHosts]; for (int i = 0; i < nHelperHosts; i++) { kvHelperHosts[i] = Text.readString(in); } kvStore = Text.readString(in); tableName = Text.readString(in); primaryKeyProperty = Text.readString(in); if (EMPTY_STR.equals(primaryKeyProperty)) { primaryKeyProperty = null; } /* For MultiRowOptions */ fieldRangeProperty = Text.readString(in); if (EMPTY_STR.equals(fieldRangeProperty)) { fieldRangeProperty = null; } /* For TableIteratorOptions */ final String dirStr = Text.readString(in); if (dirStr == null || EMPTY_STR.equals(dirStr)) { direction = Direction.UNORDERED; } else { direction = Direction.valueOf(dirStr); } final byte[] consBytes = readBytes(in); if (consBytes == null) { consistency = null; } else { consistency = Consistency.fromByteArray(consBytes); } timeout = in.readLong(); final String tuStr = Text.readString(in); if (tuStr == null || EMPTY_STR.equals(tuStr)) { timeoutUnit = null; } else { timeoutUnit = TimeUnit.valueOf(tuStr); } maxRequests = in.readInt(); batchSize = in.readInt(); maxBatches = in.readInt(); int nSets = in.readInt(); partitionSets = new ArrayList<Set<Integer>>(nSets); while (nSets > 0) { int nPartitions = in.readInt(); final Set<Integer> partitions = new HashSet<Integer>(nPartitions); partitionSets.add(partitions); while (nPartitions > 0) { partitions.add(in.readInt()); nPartitions--; } nSets--; } queryBy = in.readInt(); final int nShards = in.readInt(); shardSet = new HashSet<RepGroupId>(nShards); for (int i = 0; i < nShards; i++) { shardSet.add(new RepGroupId(in.readInt())); } /* Null where clause was serialized as empty string to avoid NPE. */ onqlWhereClause = Text.readString(in); if (EMPTY_STR.equals(onqlWhereClause)) { onqlWhereClause = null; } /* * Read the name of the login file, the user credentials (username * and password, and the name of the trust file. */ loginFlnm = Text.readString(in); if (EMPTY_STR.equals(loginFlnm)) { loginFlnm = null; } String userName = Text.readString(in); if (EMPTY_STR.equals(userName)) { userName = null; } char[] userPassword = null; final String userPasswordStr = Text.readString(in); if (userPasswordStr != null && !(EMPTY_STR.equals(userPasswordStr)) && userName != null) { userPassword = userPasswordStr.toCharArray(); pwdCredentials = new PasswordCredentials(userName, userPassword); } trustFlnm = Text.readString(in); if (EMPTY_STR.equals(trustFlnm)) { trustFlnm = null; } }
From source file:org.apache.avro.mapred.TaggedInputSplit.java
License:Apache License
@SuppressWarnings("unchecked") public void readFields(DataInput in) throws IOException { inputSplitClass = (Class<? extends InputSplit>) readClass(in); inputSplit = (InputSplit) ReflectionUtils.newInstance(inputSplitClass, conf); inputSplit.readFields(in);//from w w w . j a va2 s. c om inputFormatClass = (Class<? extends InputFormat>) readClass(in); mapperClass = (Class<? extends AvroMapper>) readClass(in); String schemaString = Text.readString(in); schema = schemaParser.parse(schemaString); }
From source file:org.apache.crunch.impl.mr.run.CrunchInputSplit.java
License:Apache License
private Class readClass(DataInput in) throws IOException { String className = Text.readString(in); try {/*from ww w. jav a 2 s .c o m*/ return conf.getClassByName(className); } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class", e); } }
From source file:org.apache.crunch.io.FormatBundle.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { this.formatClass = readClass(in); int ecSize = in.readInt(); this.extraConf = Maps.newHashMap(); for (int i = 0; i < ecSize; i++) { String key = Text.readString(in); String value = Text.readString(in); extraConf.put(key, value);//from www .ja v a2 s.c o m } }
From source file:org.apache.crunch.types.writable.GenericArrayWritable.java
License:Apache License
public void readFields(DataInput in) throws IOException { values = new Writable[WritableUtils.readVInt(in)]; // construct values if (values.length > 0) { int nulls = WritableUtils.readVInt(in); if (nulls == values.length) { return; }/*from w w w. j av a 2 s. c o m*/ String valueType = Text.readString(in); setValueType(valueType); for (int i = 0; i < values.length - nulls; i++) { Writable value = WritableFactories.newInstance(valueClass); value.readFields(in); // read a value values[i] = value; // store it in values } } }
From source file:org.apache.giraph.comm.requests.SendWorkerToWorkerMessageRequest.java
License:Apache License
@Override void readFieldsRequest(DataInput input) throws IOException { String className = Text.readString(input); try {/*from w w w . java 2 s . c o m*/ message = (Writable) Class.forName(className).newInstance(); message.readFields(input); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new IllegalStateException("readFieldsRequest: Exception occurred", e); } }
From source file:org.apache.giraph.graph.BspServiceWorker.java
License:Apache License
/** * Talk to ZooKeeper to convert the input split path to the actual * InputSplit containing the vertices to read. * * @param inputSplitPath Location in ZK of input split * @return instance of InputSplit containing vertices to read * @throws IOException//from w w w . j a v a 2 s .c om * @throws ClassNotFoundException */ private InputSplit getInputSplitForVertices(String inputSplitPath) throws IOException, ClassNotFoundException { byte[] splitList; try { splitList = getZkExt().getData(inputSplitPath, false, null); } catch (KeeperException e) { throw new IllegalStateException("loadVertices: KeeperException on " + inputSplitPath, e); } catch (InterruptedException e) { throw new IllegalStateException("loadVertices: IllegalStateException on " + inputSplitPath, e); } getContext().progress(); DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(splitList)); String inputSplitClass = Text.readString(inputStream); InputSplit inputSplit = (InputSplit) ReflectionUtils .newInstance(getConfiguration().getClassByName(inputSplitClass), getConfiguration()); ((Writable) inputSplit).readFields(inputStream); if (LOG.isInfoEnabled()) { LOG.info("getInputSplitForVertices: Reserved " + inputSplitPath + " from ZooKeeper and got input split '" + inputSplit.toString() + "'"); } return inputSplit; }
From source file:org.apache.giraph.io.GiraphInputFormat.java
License:Apache License
/** * Read input split info from DataInput. * * @param dataInput DataInput/* w ww.j a v a 2s . c o m*/ * @return InputSplit */ public InputSplit readInputSplit(DataInput dataInput) throws IOException, ClassNotFoundException { String inputSplitClass = Text.readString(dataInput); InputSplit inputSplit = (InputSplit) ReflectionUtils.newInstance(getConf().getClassByName(inputSplitClass), getConf()); ((Writable) inputSplit).readFields(dataInput); return inputSplit; }
From source file:org.apache.giraph.worker.InputSplitPathOrganizer.java
License:Apache License
/** * Utility for extracting locality data from an InputSplit ZNode. * * @param zkSplitPath the input split path to attempt to read * ZNode locality data from for this InputSplit. * @return a String of hostnames from ZNode data, or throws *//*from www .j a v a 2s . c om*/ private String getLocationsFromZkInputSplitData(String zkSplitPath) throws IOException, KeeperException, InterruptedException { byte[] locationData = zooKeeper.getData(zkSplitPath, false, null); DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(locationData)); // only read the "first" entry in the znode data, the locations return Text.readString(inputStream); }