Example usage for java.io DataOutput writeByte

List of usage examples for java.io DataOutput writeByte

Introduction

In this page you can find the example usage for java.io DataOutput writeByte.

Prototype

void writeByte(int v) throws IOException;

Source Link

Document

Writes to the output stream the eight low- order bits of the argument v.

Usage

From source file:com.ibm.jaql.util.BaseUtil.java

/**
 * /*ww w  . j av  a2  s  .  c o  m*/
 * 0x00, 0 0x01, 1 ... 0xfB 251 0xfC 1 byte pos ... 0xfe 3 byte pos 0xff 4
 * byte pos
 */
public static void writeVUInt(DataOutput out, int v) throws IOException {
    if (v <= 0xfB) // v <= 251
    {
        if (v < 0) {
            throw new IOException("positive value expected: " + v);
        }
        out.writeByte(v);
        return;
    }

    // 252 <= v <= maxInt
    v -= 0xfC;
    int len = 1;
    long t = v >> 8;
    while (t > 0) {
        t >>= 8;
        len++;
    }

    out.writeByte(0xfB + len);

    do {
        len--;
        out.writeByte(v >> (len << 3));
    } while (len > 0);
}

From source file:com.ibm.jaql.util.BaseUtil.java

/**
 * //from www .  ja  va2  s . c  o m
 * 0x00, 0 0x01, 1 ... 0xf7 247 0xf8 1 byte pos ... 0xfe 7 byte pos 0xff 8
 * byte pos
 */
public static void writeVULong(DataOutput out, long v) throws IOException {
    if (v <= 0xf7) // v <= 247
    {
        if (v < 0) {
            throw new IOException("positive value expected: " + v);
        }
        out.writeByte((int) v);
        return;
    }

    // 248 <= v <= maxLong
    v -= 0xf8;
    int len = 1;
    long t = v >> 8;
    while (t > 0) {
        t >>= 8;
        len++;
    }

    out.writeByte(0xf7 + len);

    do {
        len--;
        out.writeByte((int) (v >> (len << 3)));
    } while (len > 0);
}

From source file:com.glaf.core.util.ByteBufferUtils.java

public static void write(ByteBuffer buffer, DataOutput out) throws IOException {
    if (buffer.hasArray()) {
        out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
    } else {//from www  .  j a  v a 2  s  .  c o  m
        for (int i = buffer.position(); i < buffer.limit(); i++) {
            out.writeByte(buffer.get(i));
        }
    }
}

From source file:eu.stratosphere.types.StringValue.java

public static final void copyString(DataInput in, DataOutput out) throws IOException {
    int len = in.readUnsignedByte();
    out.writeByte(len);

    if (len >= HIGH_BIT) {
        int shift = 7;
        int curr;
        len = len & 0x7f;// www  . j  a v a2s.  c  o  m
        while ((curr = in.readUnsignedByte()) >= HIGH_BIT) {
            out.writeByte(curr);
            len |= (curr & 0x7f) << shift;
            shift += 7;
        }
        out.writeByte(curr);
        len |= curr << shift;
    }

    // note that the length is one larger than the actual length (length 0 is a null string, not a zero length string)
    len--;

    for (int i = 0; i < len; i++) {
        int c = in.readUnsignedByte();
        out.writeByte(c);
        while (c >= HIGH_BIT) {
            c = in.readUnsignedByte();
            out.writeByte(c);
        }
    }
}

From source file:com.aliyun.openservices.tablestore.hadoop.MultiCriteria.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeByte(WritableConsts.MULTI_CRITERIA);
    out.writeInt(criteria.size());/*from  w ww  .j ava 2s  .c  om*/
    for (RangeRowQueryCriteria c : criteria) {
        new RangeRowQueryCriteriaWritable(c).write(out);
    }
}

From source file:com.aliyun.openservices.tablestore.hadoop.Endpoint.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeByte(WritableConsts.ENDPOINT);
    out.writeUTF(endpoint);/*from   ww  w .  ja  v a  2s .c  o  m*/
    out.writeUTF(instance);
}

From source file:com.aliyun.openservices.tablestore.hadoop.Credential.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeByte(WritableConsts.CREDENTIAL);
    out.writeUTF(accessKeyId);/*w w  w . j a va2 s.c o  m*/
    out.writeUTF(accessKeySecret);
    if (securityToken != null) {
        out.writeByte(WritableConsts.CREDENTIAL_SECURITY_TOKEN);
        out.writeUTF(securityToken);
    }
}

From source file:com.delphix.session.util.ProtocolVersion.java

public void write(DataOutput out) throws IOException {
    out.writeByte(major);
    out.writeByte(minor);
    out.writeByte(revision);
}

From source file:libra.common.hadoop.io.datatypes.CompressedSequenceWritable.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeByte(this.seqLength);
    out.write(this.compressedSequence);
}

From source file:io.dstream.hadoop.TypeAwareWritable.java

/**
 * //from  w  ww. ja  v a2s  . co m
 */
@Override
public void write(DataOutput out) throws IOException {
    out.writeByte(this.valueType);
    if (this.valueType != NULL) {
        try {
            out.write(this.valueEncoder.valueBytes);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}