List of usage examples for org.apache.hadoop.io WritableUtils writeVInt
public static void writeVInt(DataOutput stream, int i) throws IOException
From source file:hadoop_serialize.java
License:Apache License
public static void main(String[] args) throws java.io.IOException { //System.err.println("Writing byte stream to stdout"); DataOutputStream os = new DataOutputStream(System.out); //System.err.println("Writing a sequence of numbers"); //System.err.println("WritableUtils.writeVInt: 42, 4242, 424242, 42424242, -42"); WritableUtils.writeVInt(os, 42); WritableUtils.writeVInt(os, 4242);// w ww . ja v a 2s .c o m WritableUtils.writeVInt(os, 424242); WritableUtils.writeVInt(os, 42424242); WritableUtils.writeVInt(os, -42); //System.err.println("WritableUtils.writeVLong 42, 424242, 4242424242"); WritableUtils.writeVLong(os, 42L); WritableUtils.writeVLong(os, 424242L); WritableUtils.writeVLong(os, 4242424242L); // //System.err.println("WritableUtils.writeString \"hello world\""); WritableUtils.writeString(os, "hello world"); WritableUtils.writeString(os, "oggi \u00e8 gioved\u00ec"); // This file contains: writeVInt of 42, 4242, 424242, 42424242, -42; writeVLong of 42, 424242, 4242424242; 2 writeString calls //System.err.println("Text.write \"I'm a Text object\""); Text t = new Text("\u00e0 Text object"); t.write(os); os.close(); }
From source file:Assignment4_P2_StockAverageWithCombiner.StockAverage_CompositeValueWritable.java
@Override public void write(DataOutput d) throws IOException { WritableUtils.writeVInt(d, count); WritableUtils.writeString(d, average); }
From source file:babel.content.pages.Page.java
License:Apache License
public void write(DataOutput out) throws IOException { Text.writeString(out, m_pageURL); m_pageProps.write(out);//ww w . j a v a 2 s .c o m WritableUtils.writeVInt(out, m_versions.size()); for (PageVersion ver : m_versions) { ver.write(out); } }
From source file:babel.content.pages.PageVersion.java
License:Apache License
public void write(DataOutput out) throws IOException { m_verProps.write(out);// w w w . java 2 s . c o m m_contentMeta.write(out); m_parseMeta.write(out); int numLinks = (m_outLinks == null) ? 0 : m_outLinks.length; WritableUtils.writeVInt(out, numLinks); for (int i = 0; i < numLinks; i++) { m_outLinks[i].write(out); } Text.writeString(out, m_content); }
From source file:cascading.tuple.hadoop.io.HadoopTupleOutputStream.java
License:Open Source License
@Override protected void writeIntInternal(int value) throws IOException { WritableUtils.writeVInt(this, value); }
From source file:cascading.tuple.hadoop.SerializationElementWriter.java
License:Open Source License
public void write(DataOutputStream outputStream, Object object) throws IOException { Class<?> type = object.getClass(); String className = type.getName(); Integer token = tupleSerialization.getTokenFor(className); if (token == null) { if (LOG.isDebugEnabled()) LOG.debug("no serialization token found for classname: " + className); WritableUtils.writeVInt(outputStream, TupleOutputStream.WRITABLE_TOKEN); // denotes to punt to hadoop serialization WritableUtils.writeString(outputStream, className); } else//from ww w .j a v a2s. c o m WritableUtils.writeVInt(outputStream, token); Serializer serializer = serializers.get(type); if (serializer == null) { serializer = tupleSerialization.getNewSerializer(type); serializer.open(outputStream); serializers.put(type, serializer); } try { serializer.serialize(object); } catch (IOException exception) { LOG.error("failed serializing token: " + token + " with classname: " + className, exception); throw exception; } }
From source file:cascading.tuple.TupleOutputStream.java
License:Open Source License
public void writeIndexTuple(IndexTuple indexTuple) throws IOException { WritableUtils.writeVInt(this, indexTuple.getIndex()); writeTuple(indexTuple.getTuple());//from w ww. j a v a 2 s . co m }
From source file:cascading.tuple.TupleOutputStream.java
License:Open Source License
/** * Method write is used by Hadoop to write this Tuple instance out to a file. * * @throws java.io.IOException when/*w w w.java 2s.c o m*/ */ private void write(Tuple tuple) throws IOException { List<Object> elements = Tuple.elements(tuple); WritableUtils.writeVInt(this, elements.size()); for (Object element : elements) { if (element == null) { WritableUtils.writeVInt(this, 0); continue; } Class type = element.getClass(); TupleElementWriter tupleElementWriter = tupleElementWriters.get(type); if (tupleElementWriter != null) tupleElementWriter.write(this, element); else elementWriter.write(this, element); } }
From source file:cn.edu.jnu.ie.backend.NutchDocument.java
License:Apache License
public void write(DataOutput out) throws IOException { out.writeByte(VERSION);//from ww w . j av a2s.co m WritableUtils.writeVInt(out, fields.size()); for (Map.Entry<String, NutchField> entry : fields.entrySet()) { Text.writeString(out, entry.getKey()); NutchField field = entry.getValue(); field.write(out); } out.writeFloat(weight); }
From source file:cn.iie.haiep.hbase.value.Bytes.java
License:Apache License
/** * Write byte-array with a WritableableUtils.vint prefix. * @param out output stream to be written to * @param b array to write/*w w w.j av a 2s . c o m*/ * @throws IOException e */ public static void writeByteArray(final DataOutput out, final byte[] b) throws IOException { if (b == null) { WritableUtils.writeVInt(out, 0); } else { writeByteArray(out, b, 0, b.length); } }