Example usage for java.io DataOutputStream writeChar

List of usage examples for java.io DataOutputStream writeChar

Introduction

In this page you can find the example usage for java.io DataOutputStream writeChar.

Prototype

public final void writeChar(int v) throws IOException 

Source Link

Document

Writes a char to the underlying output stream as a 2-byte value, high byte first.

Usage

From source file:sk.baka.aedict.indexer.SodMain.java

private void createPackedFile() throws IOException {
    System.out.println("Packaging " + pngLengths.size() + " pngs");
    final DataOutputStream out = new DataOutputStream(
            new GZIPOutputStream(new FileOutputStream("target/sod.dat.gz")));
    try {/*from  ww w  .j a v  a 2 s. c o  m*/
        // write index table
        int offset = pngLengths.size() * 6 + 4;
        out.writeInt(pngLengths.size());
        final List<Character> kanjis = new ArrayList<Character>(pngLengths.keySet());
        for (final Character kanji : kanjis) {
            out.writeChar(kanji);
            out.writeInt(offset);
            offset += (int) pngLengths.get(kanji).length();
        }
        // write png contents
        for (final Character kanji : kanjis) {
            final InputStream in = new FileInputStream(pngLengths.get(kanji));
            try {
                IOUtils.copy(in, out);
            } finally {
                IOUtils.closeQuietly(in);
            }
        }
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:ubic.basecode.io.ByteArrayConverter.java

/**
 * @param carray/*from  w  w  w.  j  av  a2s  .co  m*/
 * @return byte[]
 */
public byte[] charArrayToBytes(char[] carray) {
    if (carray == null)
        return null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);

    try {
        for (char element : carray) {
            dos.writeChar(element);
        }
        dos.close();
        bos.close();

    } catch (IOException e) {
        // do nothing.
    }

    return bos.toByteArray();
}