Example usage for java.io DataOutput writeShort

List of usage examples for java.io DataOutput writeShort

Introduction

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

Prototype

void writeShort(int v) throws IOException;

Source Link

Document

Writes two bytes to the output stream to represent the value of the argument.

Usage

From source file:backup.store.BackupUtil.java

public static void writeShortString(String s, DataOutput out) throws IOException {
    int length = s.length();
    byte[] bs = s.getBytes();
    out.writeShort(length);
    out.write(bs);//from ww w .  ja  v a2 s  .co m
}

From source file:hivemall.fm.FFMPredictionModel.java

private static void writeEntry(@Nonnull final Entry e, final int factors, @Nonnull final float[] Vf,
        @Nonnull final DataOutput out) throws IOException {
    final float W = e.getW();
    e.getV(Vf);/*from   w ww.j a v  a  2  s.  c  om*/

    if (ArrayUtils.almostEquals(Vf, 0.f)) {
        if (HalfFloat.isRepresentable(W)) {
            out.writeByte(W_ONLY_HALF_FLOAT_ENTRY);
            out.writeShort(HalfFloat.floatToHalfFloat(W));
        } else {
            out.writeByte(W_ONLY_FLOAT_ENTRY);
            out.writeFloat(W);
        }
    } else if (isRepresentableAsHalfFloat(W, Vf)) {
        out.writeByte(HALF_FLOAT_ENTRY);
        out.writeShort(HalfFloat.floatToHalfFloat(W));
        for (int i = 0; i < factors; i++) {
            out.writeShort(HalfFloat.floatToHalfFloat(Vf[i]));
        }
    } else {
        out.writeByte(FLOAT_ENTRY);
        out.writeFloat(W);
        IOUtils.writeFloats(Vf, factors, out);
    }
}

From source file:com.buaa.cfs.io.UTF8.java

/**
 * Write a UTF-8 encoded string.//from  w w w .  j  a  va2s .  co  m
 *
 * @see DataOutput#writeUTF(String)
 */
public static int writeString(DataOutput out, String s) throws IOException {
    if (s.length() > 0xffff / 3) { // maybe too long
        LOG.warn("truncating long string: " + s.length() + " chars, starting with " + s.substring(0, 20));
        s = s.substring(0, 0xffff / 3);
    }

    int len = utf8Length(s);
    if (len > 0xffff) // double-check length
        throw new IOException("string too long!");

    out.writeShort(len);
    writeChars(out, s, 0, s.length());
    return len;
}

From source file:io.UTF8.java

public void write(DataOutput out) throws IOException {
    out.writeShort(length);
    out.write(bytes, 0, length);
}

From source file:com.buaa.cfs.io.UTF8.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeShort(length);
    out.write(bytes, 0, length);
}

From source file:com.buaa.cfs.fs.permission.FsPermission.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeShort(toShort());
}

From source file:de.hpi.fgis.hdrs.Triple.java

public static void writeTriple(DataOutput stream, Triple t) throws IOException {
    stream.writeShort(t.getSubjectLength());
    stream.writeShort(t.getPredicateLength());
    stream.writeInt(t.getObjectLength());
    stream.writeInt(t.getMultiplicity());
    if (0 < t.getSubjectLength())
        stream.write(t.getBuffer(), t.getOffset(), t.getSubjectLength());
    if (0 < t.getPredicateLength())
        stream.write(t.getBuffer(), t.getPredicateOffset(), t.getPredicateLength());
    if (0 < t.getObjectLength())
        stream.write(t.getBuffer(), t.getObjectOffset(), t.getObjectLength());
}

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

@Override
public void write(DataOutput out) throws IOException {
    int count = this.intArray.length;
    byte flag = makeFlag(count, this.intArray);
    out.writeByte(flag);/*w w  w.j ava  2s .co  m*/

    if ((flag & 0x0f) == 0x00) {
        out.writeByte(count);
    } else if ((flag & 0x0f) == 0x01) {
        out.writeShort(count);
    } else if ((flag & 0x0f) == 0x02) {
        out.writeInt(count);
    } else {
        throw new IOException("unhandled flag");
    }

    if ((flag & 0xf0) == 0x00) {
        for (int i = 0; i < count; i++) {
            out.writeByte((byte) this.intArray[i]);
        }
    } else if ((flag & 0xf0) == 0x10) {
        for (int i = 0; i < count; i++) {
            out.writeShort((short) this.intArray[i]);
        }
    } else if ((flag & 0xf0) == 0x20) {
        for (int i = 0; i < count; i++) {
            out.writeInt((int) this.intArray[i]);
        }
    } else {
        throw new IOException("unhandled flag");
    }
}

From source file:dk.statsbiblioteket.util.LineReaderTest.java

public void writeSample(DataOutput out) throws Exception {
    out.writeInt(12345);//from   w ww.  j  a v  a  2 s .  c  o m
    out.writeInt(-87);
    out.writeLong(123456789L);
    out.write("Hello World!\n".getBytes("utf-8"));
    out.write("Another world\n".getBytes("utf-8"));
    out.writeFloat(0.5f);
    out.writeBoolean(true);
    out.writeBoolean(false);
    out.writeByte(12);
    out.writeByte(-12);
    out.write(129);
    out.writeShort(-4567);
    out.writeBytes("ASCII");
}

From source file:org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMap.java

/**
 * Convert schema to binary// w  w  w .j  a  v  a 2  s. c  o  m
 */
private byte[] convertSchemaToBinary(List<ColumnSchema> columnSchemas) throws IOException {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    DataOutput dataOutput = new DataOutputStream(stream);
    dataOutput.writeShort(columnSchemas.size());
    for (ColumnSchema columnSchema : columnSchemas) {
        if (columnSchema.getColumnReferenceId() == null) {
            columnSchema.setColumnReferenceId(columnSchema.getColumnUniqueId());
        }
        columnSchema.write(dataOutput);
    }
    byte[] byteArray = stream.toByteArray();
    // Compress with snappy to reduce the size of schema
    return Snappy.rawCompress(byteArray, byteArray.length);
}