List of usage examples for org.apache.hadoop.io Text readString
public static String readString(DataInput in) throws IOException
From source file:gaffer.statistics.StatisticsUtilities.java
License:Apache License
/** * Reads a {@link Statistic} from a stream of bytes. If the statistic is one of * Gaffer's internal ones, then we get an empty version of it from the * <code>INTERNAL_STATS</code> map, clone that and then deserialise it into that. * If the statistic is not one of the internal ones, then we use reflection to * create it the first time we see it, and store the empty version of it in the * <code>EXTERNAL_STATS</code> map so that in future it can be created without * using reflection.//from w ww. j a va2s. co m * * @param in * @return * @throws IOException */ public static Statistic getStatistic(DataInput in) throws IOException { String statisticType = Text.readString(in); Statistic emptyStatistic = INTERNAL_STATS.get(statisticType); if (emptyStatistic != null) { // Need to clone the statistic so that we're not using the one in the map Statistic clonedStatistic = emptyStatistic.clone(); clonedStatistic.readFields(in); return clonedStatistic; } // See if already in the EXTERNAL_STATS map emptyStatistic = EXTERNAL_STATS.get(statisticType); // If not already in the EXTERNAL_STATS map then create it by reflection, and add the empty version of it if (emptyStatistic == null) try { Class statisticClass = Class.forName(statisticType); Object obj = statisticClass.newInstance(); if (!(obj instanceof Statistic)) { throw new IOException("Cannot instantiate Statistic of type " + statisticType); } EXTERNAL_STATS.put(statisticType, (Statistic) obj); emptyStatistic = (Statistic) obj; } catch (ClassNotFoundException e) { throw new IOException("Unknown statistic type " + statisticType + ": " + e); } catch (InstantiationException e) { throw new IOException("Unknown statistic type " + statisticType + ": " + e); } catch (IllegalAccessException e) { throw new IOException("Unknown statistic type " + statisticType + ": " + e); } Statistic clonedStatistic = emptyStatistic.clone(); clonedStatistic.readFields(in); return clonedStatistic; }
From source file:gaffer.statistics.transform.impl.StatisticsRemoverByName.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { keepRemove = KeepRemove.values()[in.readInt()]; names.clear();//from w w w. j a va 2 s. c o m int num = in.readInt(); for (int i = 0; i < num; i++) { names.add(Text.readString(in)); } }
From source file:gaffer.utils.WritableToStringConverter.java
License:Apache License
public static Writable deserialiseFromString(String serialised) throws IOException { // Convert the base64 string to a byte array byte[] b = Base64.decodeBase64(serialised); // Deserialise the writable from the byte array ByteArrayInputStream bais = new ByteArrayInputStream(b); DataInput in = new DataInputStream(bais); String className = Text.readString(in); try {/*from w w w. j a v a 2 s . com*/ Writable writable = (Writable) Class.forName(className).newInstance(); writable.readFields(in); return writable; } catch (InstantiationException e) { throw new IOException("Exception deserialising writable: " + e); } catch (IllegalAccessException e) { throw new IOException("Exception deserialising writable: " + e); } catch (ClassNotFoundException e) { throw new IOException("Exception deserialising writable: " + e); } catch (ClassCastException e) { throw new IOException("Exception deserialising writable: " + e); } }
From source file:gobblin.data.management.copy.OwnerAndPermission.java
License:Apache License
@Override public void readFields(DataInput dataInput) throws IOException { this.owner = Text.readString(dataInput); this.group = Text.readString(dataInput); this.fsPermission = FsPermission.read(dataInput); }
From source file:gobblin.metastore.MysqlStateStore.java
License:Apache License
protected List<T> getAll(String storeName, String tableName, boolean useLike) throws IOException { List<T> states = Lists.newArrayList(); try (Connection connection = dataSource.getConnection(); PreparedStatement queryStatement = connection .prepareStatement(useLike ? SELECT_JOB_STATE_WITH_LIKE_SQL : SELECT_JOB_STATE_SQL)) { queryStatement.setString(1, storeName); queryStatement.setString(2, tableName); 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); }/* w ww. j a v a 2 s.c o m*/ } catch (EOFException e) { // no more data. GZIPInputStream.available() doesn't return 0 until after EOF. } } } } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new IOException( "failure retrieving state from storeName " + storeName + " tableName " + tableName, e); } return states; }
From source file:gr.ntua.h2rdf.inputFormat.MyFileSplit.java
License:Open Source License
public void readFields(DataInput in) throws IOException { file = new Path(Text.readString(in)); start = in.readLong();/* ww w . j a va 2 s .co m*/ length = in.readLong(); hosts = null; }
From source file:infinidb.hadoop.example.InfiniDoopRecord.java
License:Apache License
public void readFields(DataInput in) throws IOException { this.id = in.readLong(); this.name = Text.readString(in); }
From source file:io.amient.kafka.hadoop.io.KafkaInputSplit.java
License:Apache License
public void readFields(DataInput in) throws IOException { brokerId = Text.readString(in); broker = Text.readString(in); topic = Text.readString(in);//from ww w . j a v a 2 s . c o m partition = in.readInt(); startOffset = in.readLong(); }
From source file:io.confluent.connect.hdfs.wal.WALEntry.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { name = Text.readString(in); }
From source file:io.hops.erasure_coding.PolicyInfo.java
License:Apache License
public void readFields(DataInput in) throws IOException { String text = Text.readString(in); if (text.length() == 0) { this.srcPath = null; } else {//www .j a v a2 s.co m this.srcPath = new Path(text); } this.policyName = Text.readString(in); this.codecId = Text.readString(in); this.description = Text.readString(in); for (int n = in.readInt(); n > 0; n--) { String name = Text.readString(in); String value = Text.readString(in); properties.setProperty(name, value); } }