Java 8 DataOutputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DataOutputStream class.

This code example shows how to use the following methods:writeBoolean, writeByte, writeShort, close
        try { 
            messageOutputStream = channelAssociation.acquireChannelMessageOutputStream();
        } catch (Exception e) {
            throw EjbMessages.MESSAGES.failedToOpenMessageOutputStream(e);
        } 
        dataOutputStream = new DataOutputStream(messageOutputStream);
        try { 
            // write header 
            dataOutputStream.writeByte(HEADER_TX_INVOCATION_RESPONSE);
            // write invocation id 
            dataOutputStream.writeShort(invocationId);
            // write a "bit" to indicate that this message contains the XAResource status for a "prepare" 
            // invocation 
            dataOutputStream.writeBoolean(true);
            // write the XAResource status 
            PackedInteger.writePackedInteger(dataOutputStream, xaResourceStatusCode);
        } finally { 
            channelAssociation.releaseChannelMessageOutputStream(messageOutputStream);
            dataOutputStream.close();
        } 

9
CodeRank
This code example shows how to use the following methods:writeInt, writeShort, write
	@Override 
	public void writeData(DataOutputStream data) throws IOException {
 
		super.writeData(data);
 
		data.writeInt(slot);
		if (stack != null) {
			data.writeInt(stack.itemID);
			data.writeInt(stack.stackSize);
			data.writeInt(stack.getItemDamage());
			 
			if(stack.hasTagCompound()) {
				byte[] compressed = CompressedStreamTools.compress(stack.getTagCompound());
				data.writeShort(compressed.length);
				data.write(compressed);
			} else { 
				data.writeShort(0);
			} 
 
		} else { 

9
CodeRank
This code example shows how to use the following methods:writeByte, writeShort, close
    public void testUnsignedRead() throws Exception 
    { 
        byte[] testData;
 
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(baos);
        try 
        { 
            // byte 
            out.writeByte(0x1);
            // short 
            out.writeShort(1);
            testData = baos.toByteArray();
        } 
        finally 
        { 
            out.close();
        } 
 
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(testData));

9
CodeRank
This code example shows how to use the following methods:writeBoolean, writeInt
		return pipeConnectionMatrix.isDirty() || textureMatrix.isDirty() || facadeMatrix.isDirty() || plugMatrix.isDirty();
	} 
 
	@Override 
	public void writeData(DataOutputStream data) throws IOException {
		data.writeBoolean(hasGate);
		data.writeInt(gateIconIndex);
		pipeConnectionMatrix.writeData(data);
		textureMatrix.writeData(data);
		wireMatrix.writeData(data);
		facadeMatrix.writeData(data);
		plugMatrix.writeData(data);
	} 
 
	@Override 
	public void readData(DataInputStream data) throws IOException {
		hasGate = data.readBoolean();
		gateIconIndex = data.readInt();
		pipeConnectionMatrix.readData(data);
		textureMatrix.readData(data);
8
CodeRank
This code example shows how to use the following methods:close
  public final void write(DataOutput out) throws IOException {
    if (compressed == null) {
      ByteArrayOutputStream deflated = new ByteArrayOutputStream();
      Deflater deflater = new Deflater(Deflater.BEST_SPEED);
      DataOutputStream dout =
        new DataOutputStream(new DeflaterOutputStream(deflated, deflater));
      writeCompressed(dout);
      dout.close();
      deflater.end();
      compressed = deflated.toByteArray();
    } 
    out.writeInt(compressed.length);
    out.write(compressed);
  } 
 
  /** Subclasses implement this instead of {@link #write(DataOutput)}. */ 
  protected abstract void writeCompressed(DataOutput out) throws IOException;
 
} 
9
CodeRank
This code example shows how to use the following methods:writeInt, writeLong
 
    public static class IndexSummarySerializer 
    { 
        public void serialize(IndexSummary t, DataOutputStream out, boolean withSamplingLevel) throws IOException
        { 
            out.writeInt(t.indexInterval);
            out.writeInt(t.summarySize);
            out.writeLong(t.bytes.size());
            if (withSamplingLevel)
            { 
                out.writeInt(t.samplingLevel);
                out.writeInt(t.sizeAtFullSampling);
            } 
            FBUtilities.copy(new MemoryInputStream(t.bytes), out, t.bytes.size());
        } 
 
        public IndexSummary deserialize(DataInputStream in, IPartitioner partitioner, boolean haveSamplingLevel, int expectedIndexInterval) throws IOException
        { 
            int indexInterval = in.readInt();
            if (indexInterval != expectedIndexInterval)
8
CodeRank
This code example shows how to use the following methods:
    } 
 
    private void checkReadWrite(ByteBuffer bb) throws IOException
    { 
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(bos);
        ByteBufferUtil.writeWithLength(bb, out);
        ByteBufferUtil.writeWithShortLength(bb, out);
 
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
        assert bb.equals(ByteBufferUtil.readWithLength(in));
        assert bb.equals(ByteBufferUtil.readWithShortLength(in));
    } 
 
    @Test 
    public void testInputStream() throws IOException 
    { 
        ByteBuffer bb = ByteBuffer.allocate(13);
        bb.putInt(255);
        bb.put((byte) -3);
8
CodeRank
This code example shows how to use the following methods:close, write
    utilTest.checkUserDir();
    utilTest.redirectIfAntJunit();
  } 
 
  protected void createInput() throws IOException { 
    DataOutputStream out = new DataOutputStream(new FileOutputStream(INPUT_FILE.getAbsoluteFile()));
    out.write(input.getBytes("UTF-8"));
    out.close();
  } 
 
  protected String[] genArgs() {
    return new String[] {
      "-input", INPUT_FILE.getAbsolutePath(),
      "-output", OUTPUT_DIR.getAbsolutePath(),
      "-mapper", map,
      "-reducer", reduce,
      "-jobconf", "mapreduce.task.files.preserve.failedtasks=true", 
      "-jobconf", "stream.tmpdir="+System.getProperty("test.build.data","/tmp"),
      "-io", "typedbytes" 
    }; 
8
CodeRank
This code example shows how to use the following methods:writeByte, writeInt
	} 
 
	@Override 
	public void writeData(DataOutputStream data) throws IOException {
 
		data.writeInt(posX);
		data.writeInt(posY);
		data.writeInt(posZ);
 
		if (payload != null) {
			data.writeByte(payload.getType().ordinal());
			payload.writeData(data);
		} else { 
			data.writeByte(0);
		} 
	} 
 
	@Override 
	public void readData(DataInputStream data) throws IOException {
 
8
CodeRank
This code example shows how to use the following methods:flush
  } 
 
  private byte[] getByteArrayBytes(SortableBytes thingie1) throws IOException
  { 
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    thingie1.toBytesWritable().write(out);
    out.flush();
    return baos.toByteArray();
  } 
 
  private byte[] toBytes(String string)
  { 
    return string.getBytes(Charsets.UTF_8);
  } 
 
  private String fromBytes(byte[] bytes)
  { 
    return new String(bytes, Charsets.UTF_8);
  } 
8
CodeRank

Related Java 8 DataOutputStream Questions & Answers:

See Code Examples for Java 8 DataOutputStream Methods: