use of com.google.common.io.LittleEndianDataOutputStream in project tutorials by eugenp.
the class GuavaIOUnitTest method whenWriteReadLittleEndian_thenCorrect.
@Test
public void whenWriteReadLittleEndian_thenCorrect() throws IOException {
final int value = 100;
final LittleEndianDataOutputStream writer = new LittleEndianDataOutputStream(new FileOutputStream("src/test/resources/test_le.txt"));
writer.writeInt(value);
writer.close();
final LittleEndianDataInputStream reader = new LittleEndianDataInputStream(new DataInputStream(new FileInputStream("src/test/resources/test_le.txt")));
final int result = reader.readInt();
reader.close();
assertEquals(value, result);
}
use of com.google.common.io.LittleEndianDataOutputStream in project GltfSerializers by opensourceBIM.
the class BinaryGltfSerializer method write.
@Override
protected boolean write(OutputStream outputStream, ProgressReporter progressReporter) throws SerializerException {
gltfNode = OBJECT_MAPPER.createObjectNode();
buffers = OBJECT_MAPPER.createObjectNode();
meshes = OBJECT_MAPPER.createObjectNode();
buffersViews = OBJECT_MAPPER.createObjectNode();
scenesNode = OBJECT_MAPPER.createObjectNode();
accessors = OBJECT_MAPPER.createObjectNode();
nodes = OBJECT_MAPPER.createObjectNode();
materials = OBJECT_MAPPER.createObjectNode();
shaders = OBJECT_MAPPER.createObjectNode();
gltfNode.set("meshes", meshes);
gltfNode.set("bufferViews", buffersViews);
gltfNode.set("scenes", scenesNode);
gltfNode.set("accessors", accessors);
gltfNode.set("nodes", nodes);
gltfNode.set("buffers", buffers);
gltfNode.set("materials", materials);
gltfNode.set("shaders", shaders);
createVertexColorMaterial();
try {
LittleEndianDataOutputStream dataOutputStream = new LittleEndianDataOutputStream(outputStream);
generateSceneAndBody();
// StringWriter stringWriter = new StringWriter();
// OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValue(stringWriter, gltfNode);
// System.out.println(stringWriter);
byte[] sceneBytes = gltfNode.toString().getBytes(Charsets.UTF_8);
writeHeader(dataOutputStream, 20, sceneBytes.length, body.capacity());
writeScene(dataOutputStream, sceneBytes);
writeBody(dataOutputStream, body.array());
} catch (IOException e) {
throw new SerializerException(e);
}
return false;
}
use of com.google.common.io.LittleEndianDataOutputStream in project GltfSerializers by opensourceBIM.
the class BinaryGltfSerializer2 method write.
@Override
protected boolean write(OutputStream outputStream, ProgressReporter progressReporter) throws SerializerException {
gltfNode = OBJECT_MAPPER.createObjectNode();
buffers = OBJECT_MAPPER.createArrayNode();
meshes = OBJECT_MAPPER.createArrayNode();
buffersViews = OBJECT_MAPPER.createArrayNode();
scenesNode = OBJECT_MAPPER.createArrayNode();
accessors = OBJECT_MAPPER.createArrayNode();
nodes = OBJECT_MAPPER.createArrayNode();
materials = OBJECT_MAPPER.createArrayNode();
shaders = OBJECT_MAPPER.createObjectNode();
gltfNode.set("meshes", meshes);
gltfNode.set("bufferViews", buffersViews);
gltfNode.set("scenes", scenesNode);
gltfNode.set("accessors", accessors);
gltfNode.set("nodes", nodes);
gltfNode.set("buffers", buffers);
gltfNode.set("materials", materials);
// gltfNode.set("shaders", shaders);
createVertexColorMaterial();
try {
LittleEndianDataOutputStream dataOutputStream = new LittleEndianDataOutputStream(outputStream);
generateSceneAndBody();
// StringWriter stringWriter = new StringWriter();
// OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValue(stringWriter, gltfNode);
// System.out.println(stringWriter);
byte[] sceneBytes = gltfNode.toString().getBytes(Charsets.UTF_8);
writeHeader(dataOutputStream, 12, 8 + sceneBytes.length + (sceneBytes.length % 4 == 0 ? 0 : 4 - sceneBytes.length % 4), 8 + body.capacity() + (body.capacity() % 4 == 4 ? 0 : 4 - body.capacity() % 4));
writeScene(dataOutputStream, sceneBytes);
writeBody(dataOutputStream, body.array());
dataOutputStream.flush();
} catch (IOException e) {
throw new SerializerException(e);
}
return false;
}
use of com.google.common.io.LittleEndianDataOutputStream in project ultimate-java by pantinor.
the class SaveGame method write.
public void write(String strFilePath) throws Exception {
FileOutputStream fos = new FileOutputStream(strFilePath);
LittleEndianDataOutputStream dos = new LittleEndianDataOutputStream(fos);
dos.writeInt(unknown1);
dos.writeInt(moves);
for (int i = 0; i < 8; i++) {
if (players[i] == null) {
players[i] = new SaveGamePlayerRecord();
}
players[i].write(dos);
}
dos.writeInt(food);
dos.writeShort(gold);
for (int i = 0; i < 8; i++) {
dos.writeShort(karma[i]);
}
dos.writeShort(torches);
dos.writeShort(gems);
dos.writeShort(keys);
dos.writeShort(sextants);
for (int i = 0; i < 8; i++) {
dos.writeShort(armor[i]);
}
for (int i = 0; i < 16; i++) {
dos.writeShort(weapons[i]);
}
for (int i = 0; i < 8; i++) {
dos.writeShort(reagents[i]);
}
for (int i = 0; i < SPELL_MAX; i++) {
dos.writeShort(mixtures[i]);
}
dos.writeShort(items);
dos.writeByte(x);
dos.writeByte(y);
dos.writeByte(stones);
dos.writeByte(runes);
dos.writeShort(members);
dos.writeShort(transport);
dos.writeShort(balloonstate);
dos.writeShort(trammelphase);
dos.writeShort(feluccaphase);
dos.writeShort(shiphull);
dos.writeShort(lbintro);
dos.writeShort(lastcamp);
dos.writeShort(lastreagent);
dos.writeShort(lastmeditation);
dos.writeShort(lastvirtue);
dos.writeByte(dngx);
dos.writeByte(dngy);
dos.writeShort(orientation);
dos.writeShort(dnglevel);
dos.writeShort(location);
dos.writeShort(balloonfound);
dos.writeShort(balloonx);
dos.writeShort(balloony);
dos.writeByte(lastrage);
dos.writeByte(lastmask);
dos.writeByte(0);
dos.writeByte(0);
for (byte b : monster_save_tileids) {
dos.writeByte(b);
}
for (byte b : objects_save_tileids) {
dos.writeByte(b);
}
for (byte b : monster_save_x) {
dos.writeByte(b);
}
for (byte b : objects_save_x) {
dos.writeByte(b);
}
for (byte b : monster_save_y) {
dos.writeByte(b);
}
for (byte b : objects_save_y) {
dos.writeByte(b);
}
dos.close();
}
Aggregations