From c46baa35242e8e080ded90f97ef8cd4c3b5ba6b9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 17 Oct 2013 15:10:40 -0500 Subject: [PATCH] Add a minimal implementation of DataOutputStream This implements all the methods required by the DataOutput interface; to run Bio-Formats' bfconvert tool, actually only the write() and writeByte() methods would be required. Signed-off-by: Johannes Schindelin --- classpath/java/io/DataOutputStream.java | 97 +++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 classpath/java/io/DataOutputStream.java diff --git a/classpath/java/io/DataOutputStream.java b/classpath/java/io/DataOutputStream.java new file mode 100644 index 0000000000..6380e0cbd1 --- /dev/null +++ b/classpath/java/io/DataOutputStream.java @@ -0,0 +1,97 @@ +/* Copyright (c) 2008-2013, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.io; + +public class DataOutputStream extends OutputStream implements DataOutput { + private OutputStream out; + + public DataOutputStream(OutputStream out) { + this.out = out; + } + + public void close() throws IOException { + out.close(); + } + + public void flush() throws IOException { + out.flush(); + } + + public void write(byte[] buffer) throws IOException { + out.write(buffer); + } + + public void write(byte[] buffer, int offset, int length) throws IOException { + out.write(buffer, offset, length); + } + + public void write(int b) throws IOException { + out.write(b); + } + + public void writeBoolean(boolean b) throws IOException { + writeByte(b ? 1 : 0); + } + + public void writeByte(int b) throws IOException { + out.write(b); + } + + public void writeShort(int s) throws IOException { + write((byte)(s >> 8)); + write((byte)s); + } + + public void writeInt(int i) throws IOException { + write((byte)(i >> 24)); + write((byte)(i >> 16)); + write((byte)(i >> 8)); + write((byte)i); + } + + public void writeFloat(float f) throws IOException { + writeInt(Float.floatToIntBits(f)); + } + + public void writeDouble(double d) throws IOException { + writeLong(Double.doubleToLongBits(d)); + } + + public void writeLong(long l) throws IOException { + write((byte)(l >> 56)); + write((byte)(l >> 48)); + write((byte)(l >> 40)); + write((byte)(l >> 32)); + write((byte)(l >> 24)); + write((byte)(l >> 16)); + write((byte)(l >> 8)); + write((byte)l); + } + + public void writeChar(int ch) throws IOException { + write((byte)(ch >> 8)); + write((byte)ch); + } + + public void writeChars(String s) throws IOException { + for (char ch : s.toCharArray()) { + writeChar(ch & 0xffff); + } + } + + public void writeBytes(String s) throws IOException { + out.write(s.getBytes()); + } + + public void writeUTF(String s) throws IOException { + out.write(s.getBytes("UTF-8")); + } +}