Java Code Examples for java.io.DataOutput
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project Flume-Hive, under directory /src/java/com/cloudera/flume/handlers/batch/.
Source file: BatchingDecorator.java

Event batchevent(List<Event> evts) throws IOException { ByteArrayOutputStream baos=new ByteArrayOutputStream(2 >> 15); DataOutput out=new DataOutputStream(baos); for ( Event evt : events) { WriteableEvent we=new WriteableEvent(evt); we.write(out); } Event be=new EventImpl(new byte[0]); ByteBuffer b=ByteBuffer.allocate(4); b.putInt(events.size()); be.set(BATCH_SIZE,b.array()); be.set(BATCH_DATA,baos.toByteArray()); return be; }
Example 2
From project flume_1, under directory /flume-core/src/main/java/com/cloudera/flume/handlers/batch/.
Source file: BatchingDecorator.java

Event batchevent(List<Event> evts) throws IOException { ByteArrayOutputStream baos=new ByteArrayOutputStream(2 >> 15); DataOutput out=new DataOutputStream(baos); for ( Event evt : events) { WriteableEvent we=new WriteableEvent(evt); we.write(out); } Event be=new EventImpl(new byte[0]); ByteBuffer b=ByteBuffer.allocate(4); b.putInt(events.size()); be.set(BATCH_SIZE,b.array()); be.set(BATCH_DATA,baos.toByteArray()); return be; }
Example 3
From project giraph, under directory /src/main/java/org/apache/giraph/utils/.
Source file: WritableUtils.java

/** * Write object to a byte array. * @param writableObject Object to write from. * @return Byte array with serialized object. */ public static byte[] writeToByteArray(Writable writableObject){ ByteArrayOutputStream outputStream=new ByteArrayOutputStream(); DataOutput output=new DataOutputStream(outputStream); try { writableObject.write(output); } catch ( IOException e) { throw new IllegalStateException("writeToByteArray: IOStateException",e); } return outputStream.toByteArray(); }
Example 4
From project goldenorb, under directory /src/main/java/org/goldenorb/zookeeper/.
Source file: ZookeeperUtils.java

/** * @param w - Writable * @returns byte[] */ public static byte[] writableToByteArray(Writable w) throws IOException { ByteArrayOutputStream baos=new ByteArrayOutputStream(); DataOutput out=new DataOutputStream(baos); w.write(out); return baos.toByteArray(); }
Example 5
From project gora, under directory /gora-core/src/test/java/org/apache/gora/util/.
Source file: TestWritableUtils.java

@Test public void testWritesReads() throws Exception { Properties props=new Properties(); props.put("keyBlah","valueBlah"); props.put("keyBlah2","valueBlah2"); ByteArrayOutputStream bos=new ByteArrayOutputStream(); DataOutput out=new DataOutputStream(bos); WritableUtils.writeProperties(out,props); DataInput in=new DataInputStream(new ByteArrayInputStream(bos.toByteArray())); Properties propsRead=WritableUtils.readProperties(in); Assert.assertEquals(propsRead.get("keyBlah"),props.get("keyBlah")); Assert.assertEquals(propsRead.get("keyBlah2"),props.get("keyBlah2")); }
Example 6
From project activemq-apollo, under directory /apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/.
Source file: XidImpl.java

/** * Writes this XidImpl's data to the DataOutput destination * @param out The DataOutput destination */ public void writebody(DataOutput out) throws IOException { out.writeInt(formatId); out.writeInt(globalTransactionId.length); out.write(globalTransactionId.data,globalTransactionId.offset,globalTransactionId.length); out.writeInt(branchQualifier.length); out.write(branchQualifier.data,branchQualifier.offset,branchQualifier.length); }
Example 7
From project asakusafw-examples, under directory /example-seqfile/src/main/java/com/asakusafw/example/direct/seqfile/writable/.
Source file: ItemInfoWritable.java

@Override public void write(DataOutput out) throws IOException { Text.writeString(out,itemName); Text.writeString(out,departmentCode); Text.writeString(out,departmentName); Text.writeString(out,categoryCode); Text.writeString(out,categoryName); out.writeInt(unitSellingPrice); out.writeLong(registeredDate.getTime()); out.writeLong(beginDate.getTime()); out.writeLong(endDate.getTime()); }
Example 8
From project action-core, under directory /src/main/java/com/ning/metrics/action/hdfs/data/.
Source file: RowSmile.java

/** * Serialize the row into the DataOutput * @param out DataOutput to write * @throws java.io.IOException generic serialization error */ @Override public void write(DataOutput out) throws IOException { schema.write(out); WritableUtils.writeVInt(out,data.size()); ByteArrayOutputStream outStream=new ByteArrayOutputStream(); JsonGenerator gen=objectMapper.getJsonFactory().createJsonGenerator(outStream,JsonEncoding.UTF8); for ( JsonNodeComparable dataItem : data) { objectMapper.writeValue(gen,dataItem); } gen.close(); WritableUtils.writeVInt(out,outStream.size()); out.write(outStream.toByteArray()); }
Example 9
From project archive-commons, under directory /ia-tools/src/main/java/org/archive/hadoop/io/.
Source file: MergeClusterRangesInputSplit.java

public void write(DataOutput out) throws IOException { out.writeLong(length); out.writeUTF(start); out.writeUTF(end); out.writeInt(clusterPaths.length); for ( String p : clusterPaths) { out.writeUTF(p); } }
Example 10
From project ARCInputFormat, under directory /src/org/commoncrawl/hadoop/io/.
Source file: ARCSplit.java

/** * @inheritDoc */ public void write(DataOutput out) throws IOException { out.writeInt(resources.length); for ( ARCResource resource : resources) { resource.write(out); } out.writeLong(size); }
Example 11
public void write(DataOutput out) throws IOException { Text.writeString(out,m_pageURL); m_pageProps.write(out); WritableUtils.writeVInt(out,m_versions.size()); for ( PageVersion ver : m_versions) { ver.write(out); } }
Example 12
From project Baseform-Epanet-Java-Library, under directory /src/org/addition/epanet/hydraulic/io/.
Source file: AwareStep.java

public static void writeHeader(DataOutput outStream,HydraulicSim hydraulicSim,long rstart,long rstep,long duration) throws IOException, ENException { outStream.writeInt(FORMAT_VERSION); outStream.writeInt(hydraulicSim.getnNodes().size()); outStream.writeInt(hydraulicSim.getnLinks().size()); outStream.writeLong(rstart); outStream.writeLong(rstep); outStream.writeLong(duration); }
Example 13
From project BeeQueue, under directory /src/org/beequeue/piles/flock/.
Source file: ExternalizableUtil.java

public static void writeNullableUTF(DataOutput out,String s) throws IOException { boolean isNull=s == null; out.writeBoolean(isNull); if (!isNull) { out.writeUTF(s); } }
Example 14
From project behemoth, under directory /core/src/main/java/com/digitalpebble/behemoth/.
Source file: BehemothDocument.java

public void writeCommon(DataOutput out) throws IOException { out.writeByte(CUR_VERSION); Text.writeString(out,url); if (content == null) out.writeInt(0); else { out.writeInt(content.length); out.write(content); } if (contentType != null) { Text.writeString(out,contentType); } else { Text.writeString(out,""); } out.writeBoolean(text != null); if (text != null) Text.writeString(out,text); out.writeBoolean(metadata != null); if (metadata != null) metadata.write(out); }
Example 15
From project big-data-plugin, under directory /shims/common/src/org/pentaho/hbase/shim/common/.
Source file: DeserializedNumericComparator.java

@Override public void write(DataOutput out) throws IOException { out.writeBoolean(m_isInteger); out.writeBoolean(m_isLongOrDouble); out.writeLong(m_longValue); out.writeDouble(m_doubleValue); }
Example 16
From project blacktie, under directory /stompconnect-1.0/src/main/java/org/codehaus/stomp/.
Source file: StompMarshaller.java

public void marshal(StompFrame stomp,DataOutput os) throws UnsupportedEncodingException, IOException { StringBuffer buffer=new StringBuffer(); buffer.append(stomp.getAction()); buffer.append(Stomp.NEWLINE); for (Iterator iter=stomp.getHeaders().entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry=(Map.Entry)iter.next(); buffer.append(entry.getKey()); buffer.append(Stomp.Headers.SEPERATOR); buffer.append(entry.getValue()); buffer.append(Stomp.NEWLINE); } buffer.append(Stomp.NEWLINE); os.write(buffer.toString().getBytes("UTF-8")); os.write(stomp.getContent()); os.write(END_OF_FRAME); }
Example 17
From project C-Cat, under directory /util/src/main/java/gov/llnl/ontology/util/.
Source file: StringCounter.java

public void write(DataOutput out) throws IOException { out.writeInt(size()); for ( Map.Entry<String,Integer> entry : this) { out.writeUTF(entry.getKey()); out.writeInt(entry.getValue()); } }
Example 18
From project cascading, under directory /src/hadoop/cascading/tap/hadoop/io/.
Source file: MultiInputSplit.java

public void write(DataOutput out) throws IOException { out.writeUTF(inputSplit.getClass().getName()); String[] keys=config.keySet().toArray(new String[config.size()]); String[] values=new String[keys.length]; for (int i=0; i < keys.length; i++) values[i]=config.get(keys[i]); WritableUtils.writeStringArray(out,keys); WritableUtils.writeStringArray(out,values); inputSplit.write(out); }
Example 19
From project chukwa, under directory /src/main/java/org/apache/hadoop/chukwa/.
Source file: ChunkImpl.java

/** * @see org.apache.hadoop.io.Writable#write(java.io.DataOutput) */ public void write(DataOutput out) throws IOException { out.writeInt(PROTOCOL_VERSION); out.writeLong(seqID); out.writeUTF(source); out.writeUTF(tags); out.writeUTF(streamName); out.writeUTF(dataType); out.writeUTF(debuggingInfo); if (recordEndOffsets == null) recordEndOffsets=new int[]{data.length - 1}; out.writeInt(recordEndOffsets.length); for (int i=0; i < recordEndOffsets.length; ++i) out.writeInt(recordEndOffsets[i]); out.write(data,0,recordEndOffsets[recordEndOffsets.length - 1] + 1); }
Example 20
From project ciel-java, under directory /examples/Grep/src/skywriting/examples/grep/.
Source file: Text.java

/** * Serializes a long to a binary stream with zero-compressed encoding. For -112 <= i <= 127, only one byte is used with the actual value. For other values of i, the first byte value indicates whether the long is positive or negative, and the number of bytes that follow. If the first byte value v is between -113 and -120, the following long is positive, with number of bytes that follow are -(v+112). If the first byte value v is between -121 and -128, the following long is negative, with number of bytes that follow are -(v+120). Bytes are stored in the high-non-zero-byte-first order. * @param stream Binary output stream * @param i Long to be serialized * @throws java.io.IOException */ public static void writeVLong(DataOutput stream,long i) throws IOException { if (i >= -112 && i <= 127) { stream.writeByte((byte)i); return; } int len=-112; if (i < 0) { i^=-1L; len=-120; } long tmp=i; while (tmp != 0) { tmp=tmp >> 8; len--; } stream.writeByte((byte)len); len=(len < -120) ? -(len + 120) : -(len + 112); for (int idx=len; idx != 0; idx--) { int shiftbits=(idx - 1) * 8; long mask=0xFFL << shiftbits; stream.writeByte((byte)((i & mask) >> shiftbits)); } }
Example 21
From project Cloud9, under directory /src/dist/edu/umd/cloud9/collection/clue/.
Source file: ClueWarcRecord.java

/** * Serialization output * @param out the data output stream * @throws java.io.IOException */ public void write(DataOutput out) throws IOException { out.writeUTF(contentType); out.writeUTF(UUID); out.writeUTF(dateString); out.writeUTF(recordType); out.writeInt(metadata.size()); Iterator<Entry<String,String>> metadataIterator=metadata.entrySet().iterator(); while (metadataIterator.hasNext()) { Entry<String,String> thisEntry=metadataIterator.next(); out.writeUTF(thisEntry.getKey()); out.writeUTF(thisEntry.getValue()); } out.writeInt(contentLength); }
Example 22
From project CommunityCase, under directory /src/org/community/intellij/plugins/communitycase/history/.
Source file: NewUsersComponent.java

@Override public void save(DataOutput out,List<String> value) throws IOException { out.writeInt(value.size()); for ( String s : value) { out.writeUTF(s); } }
Example 23
From project core_4, under directory /impl/src/main/java/org/richfaces/renderkit/html/.
Source file: BaseGradient.java

public void writeState(FacesContext context,DataOutput dataOutput) throws IOException { writeIntegerParameterAsShort(dataOutput,this.width); writeIntegerParameterAsShort(dataOutput,this.height); writeIntegerParameterAsShort(dataOutput,this.gradientHeight); writeIntegerParameter(dataOutput,this.headerBackgroundColor); writeIntegerParameter(dataOutput,this.headerGradientColor); dataOutput.writeBoolean(this.horizontal); dataOutput.writeByte((byte)this.gradientType.ordinal()); }
Example 24
From project craftbook, under directory /oldsrc/commonrefactor/com/sk89q/craftbook/mech/ic/plc/types/.
Source file: Perlstone32_1.java

public void writeCommonData(DataOutput out) throws IOException { out.write(0); out.writeInt(publicPersistentStorage.size()); for ( String key : publicPersistentStorage.keySet()) { out.writeUTF(key); int[] data=publicPersistentStorage.get(key); out.writeInt(data.length); for ( int i : data) if (i == 0) out.writeBoolean(false); else { out.writeBoolean(true); out.writeInt(i); } } }
Example 25
From project crunch, under directory /crunch/src/main/java/org/apache/crunch/impl/mr/run/.
Source file: CrunchInputSplit.java

public void write(DataOutput out) throws IOException { out.writeInt(nodeIndex); out.writeInt(extraConf.size()); for ( Map.Entry<String,String> e : extraConf.entrySet()) { out.writeUTF(e.getKey()); out.writeUTF(e.getValue()); } Text.writeString(out,inputFormatClass.getName()); Text.writeString(out,inputSplit.getClass().getName()); SerializationFactory factory=new SerializationFactory(conf); Serializer serializer=factory.getSerializer(inputSplit.getClass()); serializer.open((DataOutputStream)out); serializer.serialize(inputSplit); }
Example 26
From project culvert, under directory /culvert-main/src/main/java/com/bah/culvert/constraints/filter/.
Source file: ResultFilter.java

@Override public void write(DataOutput out) throws IOException { if (this.subConstraint == null) out.writeBoolean(false); else { out.writeBoolean(true); Constraint.write(this.subConstraint,out); } ow.set(this.columns); ow.write(out); this.range.write(out); if (this.table == null) out.writeBoolean(false); else { out.writeBoolean(true); new ObjectWritable(this.table).write(out); } }
Example 27
From project daily-money, under directory /dailymoney/src/com/bottleworks/dailymoney/calculator2/.
Source file: History.java

void write(DataOutput out) throws IOException { out.writeInt(mEntries.size()); for ( HistoryEntry entry : mEntries) { entry.write(out); } out.writeInt(mPos); }
Example 28
From project datasalt-utils, under directory /src/contrib/java/org/apache/hadoop/mapreduce/lib/input/.
Source file: TaggedInputSplit.java

@SuppressWarnings("unchecked") public void write(DataOutput out) throws IOException { Text.writeString(out,inputSplitClass.getName()); Text.writeString(out,inputFormatClass.getName()); Text.writeString(out,mapperClass.getName()); SerializationFactory factory=new SerializationFactory(conf); Serializer serializer=factory.getSerializer(inputSplitClass); serializer.open((DataOutputStream)out); serializer.serialize(inputSplit); }
Example 29
From project elephant-twin, under directory /com.twitter.elephanttwin/src/main/java/com/twitter/elephanttwin/io/.
Source file: ListLongPair.java

@Override public void write(DataOutput out) throws IOException { out.writeInt(list.size()); Iterator<LongPairWritable> itr=list.iterator(); while (itr.hasNext()) { LongPairWritable element=itr.next(); element.write(out); } }
Example 30
From project enclojure, under directory /org-enclojure-ide/src/main/java/org/enclojure/ide/asm/commons/.
Source file: SerialVersionUIDAdder.java

/** * Sorts the items in the collection and writes it to the data output stream * @param itemCollection collection of items * @param dos a <code>DataOutputStream</code> value * @param dotted a <code>boolean</code> value * @exception IOException if an error occurs */ private static void writeItems(final Collection itemCollection,final DataOutput dos,final boolean dotted) throws IOException { int size=itemCollection.size(); Item[] items=(Item[])itemCollection.toArray(new Item[size]); Arrays.sort(items); for (int i=0; i < size; i++) { dos.writeUTF(items[i].name); dos.writeInt(items[i].access); dos.writeUTF(dotted ? items[i].desc.replace('/','.') : items[i].desc); } }
Example 31
From project extramuros, under directory /java/src/extramuros/java/formats/adapters/.
Source file: TextFileTableAdapter.java

public void write(DataOutput dataOutput) throws IOException { getHeader().write(dataOutput); Text tmp=new Text(getRowsPath()); tmp.write(dataOutput); tmp=new Text(defaultSeparator); tmp.write(dataOutput); dataOutput.writeInt(nullValues.length); for ( String nullValue : nullValues) { tmp=new Text(nullValue); tmp.write(dataOutput); } }
Example 32
From project flume, under directory /flume-ng-channels/flume-file-channel/src/main/java/org/apache/flume/channel/file/.
Source file: FlumeEvent.java

@Override public void write(DataOutput out) throws IOException { MapWritable map=toMapWritable(getHeaders()); map.write(out); byte[] body=getBody(); if (body == null) { out.writeInt(-1); } else { out.writeInt(body.length); out.write(body); } }
Example 33
From project g414-hash, under directory /src/main/java/com/g414/hash/file2/impl/.
Source file: FileOperations2.java

private static void write(DataOutput out,ByteSize size,long value) throws IOException { switch (size) { case EIGHT: out.writeLong(value); break; case FOUR: if (value > Integer.MAX_VALUE) { throw new IOException("Integer overflow : " + value); } out.writeInt((int)value); break; case TWO: if (value > Character.MAX_VALUE) { throw new IOException("Character overflow : " + value); } out.writeChar((int)value); break; case ONE: if (value > Byte.MAX_VALUE) { throw new IOException("Byte overflow : " + value); } out.writeByte((int)value); break; case ZERO: if (value > 0) { throw new IOException("Expected empty value!" + value); } break; } }
Example 34
From project galaxy, under directory /src/co/paralleluniverse/galaxy/core/.
Source file: Message.java

private Streamable streamableNoBuffers(){ return new Streamable(){ @Override public int size(){ return size1(); } @Override public void write( DataOutput out) throws IOException { write1(out); } @Override public void read( DataInput in) throws IOException { read1(in); } } ; }
Example 35
From project hadoop-book_1, under directory /src/main/java/com/manning/hip/ch3/passwd/.
Source file: Passwd.java

@Override public void write(DataOutput out) throws IOException { WritableUtils.writeString(out,username); WritableUtils.writeString(out,password); writeLong(out,uid); writeLong(out,gid); WritableUtils.writeString(out,uidInfo); WritableUtils.writeString(out,homeDir); WritableUtils.writeString(out,shell); }