List of usage examples for org.apache.hadoop.io Writable write
void write(DataOutput out) throws IOException;
out
. From source file:com.bah.culvert.test.Utils.java
License:Apache License
/** * Checks if the writable will successfully read and write using * {@link Writable}'s methods.//from w w w . j a v a 2s . c o m * @param writeable * @return The instance read in using * {@link Writable#readFields(java.io.DataInput)}. Can be used for * checking equality. * @throws InstantiationException * @throws IllegalAccessException * @throws IOException */ public static Writable testReadWrite(Writable writeable) throws InstantiationException, IllegalAccessException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); writeable.write(dos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DataInputStream dis = new DataInputStream(bais); Writable inst = writeable.getClass().newInstance(); inst.readFields(dis); return inst; }
From source file:com.cloudera.bigdata.analysis.index.util.WritableUtil.java
License:Apache License
/** * Writes out the provided writable instance to the data outout. * * @param out the data output//from w ww .j a va 2 s . c om * @param writable the writable isntance (must not be null) * @throws java.io.IOException if an io error occurs */ public static void writeInstance(DataOutput out, Writable writable) throws IOException { if (writable == null) { throw new IllegalArgumentException("The writable instance must not be null"); } Bytes.writeByteArray(out, Bytes.toBytes(writable.getClass().getName())); writable.write(out); }
From source file:com.cloudera.impala.security.PersistedDelegationTokenSecretManager.java
License:Apache License
public static String encodeWritable(Writable key) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); key.write(dos); dos.flush();/*www. j ava2s. c om*/ return Base64.encodeBase64URLSafeString(bos.toByteArray()); }
From source file:com.dasasian.chok.lucene.Hit.java
License:Apache License
public void write(final DataOutput out) throws IOException { out.writeFloat(_score);/* w w w . ja v a2 s. c om*/ if (_node != null) { out.writeBoolean(true); _node.write(out); } else { out.writeBoolean(false); } _shard.write(out); out.writeInt(_docId); if (_sortFields == null) { out.writeByte(0); } else { out.writeByte(_sortFields.length); for (Writable writable : _sortFields) { writable.write(out); } } }
From source file:com.dasasian.chok.lucene.HitsMapWritable.java
License:Apache License
public void write(final DataOutput out) throws IOException { long start = 0; if (LOG.isDebugEnabled()) { start = System.currentTimeMillis(); }/* www . j a va 2 s . c o m*/ out.writeUTF(_nodeName); out.writeInt(_totalHits); if (_sortFieldTypes == null) { out.writeByte(0); } else { out.writeByte(_sortFieldTypes.length); for (WritableType writableType : _sortFieldTypes) { out.writeByte(writableType.ordinal()); } } int shardCount = _shards.size(); out.writeInt(shardCount); byte shardIndex = 0; Map<String, Byte> shardIndexByShard = new HashMap<>(shardCount); for (String shard : _shards) { out.writeUTF(shard); shardIndexByShard.put(shard, shardIndex); shardIndex++; } out.writeInt(_hits.size()); for (Hit hit : _hits) { out.writeByte(shardIndexByShard.get(hit.getShard())); out.writeFloat(hit.getScore()); out.writeInt(hit.getDocId()); WritableComparable[] sortFields = hit.getSortFields(); if (sortFields == null) { out.writeByte(0); } else { out.writeByte(sortFields.length); for (Writable writable : sortFields) { writable.write(out); } } } if (LOG.isDebugEnabled()) { final long end = System.currentTimeMillis(); LOG.debug("HitsMap writing took " + (end - start) / 1000.0 + "sec."); LOG.debug("HitsMap writing ended at: " + end + " for server " + _nodeName); } }
From source file:com.dasasian.chok.testutil.AbstractWritableTest.java
License:Apache License
protected DataOutputBuffer writeWritable(Writable writable) throws IOException { DataOutputBuffer out = new DataOutputBuffer(1024); writable.write(out); out.flush();// www . j a va2s . c o m return out; }
From source file:com.datasalt.utils.commons.WritableUtils.java
License:Apache License
/** * Serialize writable/*from w w w.j a v a2s .co m*/ */ public static byte[] serialize(Writable datum) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); datum.write(dos); return bos.toByteArray(); }
From source file:com.facebook.hiveio.common.Writables.java
License:Apache License
/** * Write an arbitrary unknown Writable. This first writes the class name of * the writable so we can read it in dynamically later. It is used together * with readUnknownWritable./*from ww w.j a v a 2 s . c o m*/ * * @param out DataOutput * @param object Writable to write * @throws IOException I/O errors */ public static void writeUnknownWritable(DataOutput out, Writable object) throws IOException { writeClassName(out, object); object.write(out); }
From source file:com.facebook.hiveio.common.Writables.java
License:Apache License
/** * Write object to a byte array./*from w w w . ja va 2 s. c o m*/ * * @param writableObject Object to write from. * @return Byte array with serialized object. */ public static byte[] writeToByteArray(Writable writableObject) { ByteArrayOutputStream os = new ByteArrayOutputStream(); DataOutput output = new DataOutputStream(os); try { writableObject.write(output); } catch (IOException e) { throw new IllegalStateException("writeToByteArray: IOStateException", e); } return os.toByteArray(); }
From source file:com.google.appengine.tools.mapreduce.v2.impl.Writables.java
License:Apache License
public static byte[] createByteArrayFromWritable(Writable w) { try {/*from w w w . j a va 2s . c o m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); w.write(dos); dos.close(); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException("Got an impossible IOException from a ByteArrayOutputStream", e); } }