diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-05-18 17:29:21 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-05-18 17:29:21 +0000 |
commit | 64089cc9f030d8ef7972adb5d117e0b23f47d62b (patch) | |
tree | 9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java | |
parent | 96034e28360d660d7a7708807fcbc4b519574d8e (diff) | |
download | ppe42-gcc-64089cc9f030d8ef7972adb5d117e0b23f47d62b.tar.gz ppe42-gcc-64089cc9f030d8ef7972adb5d117e0b23f47d62b.zip |
Imported GNU Classpath 0.90
* scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale.
* sources.am: Regenerated.
* gcj/javaprims.h: Regenerated.
* Makefile.in: Regenerated.
* gcj/Makefile.in: Regenerated.
* include/Makefile.in: Regenerated.
* testsuite/Makefile.in: Regenerated.
* gnu/java/lang/VMInstrumentationImpl.java: New override.
* gnu/java/net/local/LocalSocketImpl.java: Likewise.
* gnu/classpath/jdwp/VMMethod.java: Likewise.
* gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest
interface.
* java/lang/Thread.java: Add UncaughtExceptionHandler.
* java/lang/reflect/Method.java: Implements GenericDeclaration and
isSynthetic(),
* java/lang/reflect/Field.java: Likewise.
* java/lang/reflect/Constructor.java
* java/lang/Class.java: Implements Type, GenericDeclaration,
getSimpleName() and getEnclosing*() methods.
* java/lang/Class.h: Add new public methods.
* java/lang/Math.java: Add signum(), ulp() and log10().
* java/lang/natMath.cc (log10): New function.
* java/security/VMSecureRandom.java: New override.
* java/util/logging/Logger.java: Updated to latest classpath
version.
* java/util/logging/LogManager.java: New override.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113887 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java')
-rw-r--r-- | libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java | 75 |
1 files changed, 63 insertions, 12 deletions
diff --git a/libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java b/libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java index c708a2368d7..1179fed7dcd 100644 --- a/libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java +++ b/libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java @@ -38,7 +38,10 @@ exception statement from your version. */ package javax.imageio.stream; +import gnu.classpath.NotImplementedException; + import java.io.IOException; +import java.io.UTFDataFormatException; import java.nio.ByteOrder; /** @@ -52,8 +55,8 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl // Do nothing here. } - protected void flushBits() - throws IOException + protected final void flushBits() + throws IOException, NotImplementedException { // FIXME: Implement me. throw new Error("not implemented"); @@ -72,14 +75,14 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl throws IOException; public void writeBit(int bit) - throws IOException + throws IOException, NotImplementedException { // FIXME: Implement me. throw new Error("not implemented"); } public void writeBits(long bits, int numBits) - throws IOException + throws IOException, NotImplementedException { // FIXME: Implement me. throw new Error("not implemented"); @@ -100,13 +103,17 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl public void writeBytes(String data) throws IOException { - write(data.getBytes()); + // This is bogus, but it is how the method is specified. + // Sun ought to deprecate this method. + int len = data.length(); + for (int i = 0; i < len; ++i) + writeByte(data.charAt(i)); } public void writeChar(int value) throws IOException { - writeShort((short) value); + writeShort(value); } public void writeChars(char[] data, int offset, int len) @@ -119,14 +126,15 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl public void writeChars(String data) throws IOException { - // FIXME: Implement me. - throw new Error("not implemented"); + int len = data.length(); + for (int i = 0; i < len; ++i) + writeChar(data.charAt(i)); } public void writeDouble(double value) throws IOException { - writeLong((long) value); + writeLong(Double.doubleToLongBits(value)); } public void writeDoubles(double[] data, int offset, int len) @@ -139,7 +147,7 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl public void writeFloat(float value) throws IOException { - writeInt((int) value); + writeInt(Float.floatToIntBits(value)); } public void writeFloats(float[] data, int offset, int len) @@ -237,9 +245,52 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl writeShort(data[offset + i]); } - public void writeUTF(String data) + public void writeUTF(String value) throws IOException { - throw new Error("not implemented"); + // NOTE: this code comes directly from DataOutputStream. + int len = value.length(); + int sum = 0; + + for (int i = 0; i < len && sum <= 65535; ++i) + { + char c = value.charAt(i); + if (c >= '\u0001' && c <= '\u007f') + sum += 1; + else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) + sum += 2; + else + sum += 3; + } + + if (sum > 65535) + throw new UTFDataFormatException (); + + int pos = 0; + byte[] buf = new byte[sum]; + + for (int i = 0; i < len; ++i) + { + char c = value.charAt(i); + if (c >= '\u0001' && c <= '\u007f') + buf[pos++] = (byte) c; + else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) + { + buf[pos++] = (byte) (0xc0 | (0x1f & (c >> 6))); + buf[pos++] = (byte) (0x80 | (0x3f & c)); + } + else + { + // JSL says the first byte should be or'd with 0xc0, but + // that is a typo. Unicode says 0xe0, and that is what is + // consistent with DataInputStream. + buf[pos++] = (byte) (0xe0 | (0x0f & (c >> 12))); + buf[pos++] = (byte) (0x80 | (0x3f & (c >> 6))); + buf[pos++] = (byte) (0x80 | (0x3f & c)); + } + } + + writeShort (sum); + write(buf, 0, sum); } } |