
co.paralleluniverse.io.serialization.kryo.KryoObjectOutputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quasar-core Show documentation
Show all versions of quasar-core Show documentation
Fibers, Channels and Actors for the JVM
/*
* Copyright (c) 2013-2014, Parallel Universe Software Co. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 3.0
* as published by the Free Software Foundation.
*/
package co.paralleluniverse.io.serialization.kryo;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Output;
import java.io.DataOutput;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.OutputStream;
/**
*
* @author pron
*/
class KryoObjectOutputStream extends OutputStream implements DataOutput, ObjectOutput {
private final Output out;
private final Kryo kryo;
public KryoObjectOutputStream(Output out, Kryo kryo) {
this.out = out;
this.kryo = kryo;
}
@Override
public void writeChar(int v) throws IOException {
writeChar((char) v);
}
@Override
public void writeBytes(String s) throws IOException {
int len = s.length();
for (int i = 0; i < len; i++) {
write((byte) s.charAt(i));
}
}
@Override
public void writeChars(String s) throws IOException {
int len = s.length();
for (int i = 0; i < len; i++) {
int v = s.charAt(i);
write((v >>> 8) & 0xFF);
write(v & 0xFF);
}
}
@Override
public void writeUTF(String s) throws IOException {
out.writeString(s);
}
@Override
public void writeObject(Object obj) throws IOException {
kryo.writeClassAndObject(out, obj);
}
@Override
public void write(int b) throws IOException {
out.write(b);
}
@Override
public void writeBoolean(boolean v) throws IOException {
out.writeBoolean(v);
}
@Override
public void writeByte(int v) throws IOException {
out.writeByte(v);
}
@Override
public void writeShort(int v) throws IOException {
out.writeShort(v);
}
@Override
public void writeInt(int v) throws IOException {
out.writeInt(v);
}
@Override
public void writeLong(long v) throws IOException {
out.writeLong(v);
}
@Override
public void writeFloat(float v) throws IOException {
out.writeFloat(v);
}
@Override
public void writeDouble(double v) throws IOException {
out.writeDouble(v);
}
@Override
public void write(byte[] b) throws IOException {
out.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
out.write(b, off, len);
}
@Override
public void flush() throws IOException {
out.flush();
}
@Override
public void close() throws IOException {
out.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy