From e0441a5bfb29083a532307ba2b1fd6d6d13944ba Mon Sep 17 00:00:00 2001 From: Matthias Klose Date: Sat, 28 Jun 2008 13:29:13 +0000 Subject: Import GNU Classpath (classpath-0_97_2-release). libjava/ 2008-06-28 Matthias Klose Import GNU Classpath (classpath-0_97_2-release). * Regenerate class and header files. * Regenerate auto* files. * gcj/javaprims.h: Define jobjectRefType. * jni.cc (_Jv_JNI_GetObjectRefType): New (stub only). (_Jv_JNIFunctions): Initialize GetObjectRefType. * gnu/classpath/jdwp/VMVirtualMachine.java, java/security/VMSecureRandom.java: Merge from classpath. * HACKING: Fix typo. * ChangeLog-2007: New file. * configure.ac: Set JAVAC, pass --disable-regen-headers to classpath. libjava/classpath/ 2008-06-28 Matthias Klose * m4/ac_prog_javac.m4: Disable check for JAVAC, when not configured with --enable-java-maintainer-mode. * aclocal.m4, configure: Regenerate. * native/jni/gstreamer-peer/Makefile.am: Do not link with libclasspathnative. * native/jni/gstreamer-peer/Makefile.in: Regenerate. * tools/Makefile.am, lib/Makefile.am: Use JAVAC for setting JCOMPILER, drop flags not understood by gcj. From-SVN: r137223 --- libjava/classpath/java/io/DataOutputStream.java | 84 ++++++++++++++++++++----- 1 file changed, 67 insertions(+), 17 deletions(-) (limited to 'libjava/classpath/java/io/DataOutputStream.java') diff --git a/libjava/classpath/java/io/DataOutputStream.java b/libjava/classpath/java/io/DataOutputStream.java index 6670c2dba13..435ff76d13e 100644 --- a/libjava/classpath/java/io/DataOutputStream.java +++ b/libjava/classpath/java/io/DataOutputStream.java @@ -1,5 +1,5 @@ /* DataOutputStream.java -- Writes primitive Java datatypes to streams - Copyright (C) 1998, 2001, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2003, 2005, 2008 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -379,19 +379,20 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput /** * Calculate the length, in bytes, of a String in Utf8 format. + * This method is package-private so that ObjectOutputStream + * may use it. The return type is long so that a long string whose + * Utf8 byte count is 64 bit long may be handled. * * @param value The String to measure * @param start String index at which to begin count * @param sum Starting Utf8 byte count * - * @throws UTFDataFormatException if result would exceed 65535 */ - private int getUTFlength(String value, int start, int sum) - throws IOException + long getUTFlength(String value, int start, long sum) { int len = value.length(); - for (int i = start; i < len && sum <= 65535; ++i) + for (int i = start; i < len; ++i) { char c = value.charAt(i); if (c >= '\u0001' && c <= '\u007f') @@ -402,9 +403,6 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput sum += 3; } - if (sum > 65535) - throw new UTFDataFormatException (); - return sum; } @@ -441,11 +439,71 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * @see DataInput#readUTF */ public final synchronized void writeUTF(String value) throws IOException + { + long l = getUTFlength(value, 0, 0); + if (l > 65535) + throw new UTFDataFormatException (); + writeUTFShort(value, (int)l); + } + + /** + * This method performs the main task of writeUTF. + * This method is package-private because ObjectOutputStream uses it. + * + * @param value The String to write to the output in UTF format + * + * @param bytelen The UTF-8 byte length of the String. When + * this method is called, the expected byte length must have been calculated + * by getUTFlength. + * + * @exception IOException If an error occurs + * + * @see DataInput#readUTF + */ + final synchronized void writeUTFShort(String value, int bytelen) + throws IOException + { + writeShort(bytelen); + writeUTFBytes(value); + } + + /** + * This method is similar to writeUTF, but it writes the + * UTF-8 byte length in 64 bits. + * This method is not public but ObjectOutputStream uses it. + * + * @param value The String to write to the output in UTF format + * + * @param bytelen The UTF-8 byte length of the String. When + * this method is called, the expected byte length must have been calculated + * by getUTFlength. + * + * @exception IOException If an error occurs + * + */ + final synchronized void writeUTFLong(String value, long bytelen) + throws IOException + { + writeLong(bytelen); + writeUTFBytes(value); + } + + /** + * This method performes the main task of writeUTF and + * WriteUTFLong, which is to write the UTF-8 byte + * sequence to the output. + * + * @param value The String to write to the output in UTF format + * + * @exception IOException If an error occurs + * + */ + private final synchronized void writeUTFBytes(String value) + throws IOException { int len = value.length(); int i = 0; int pos = 0; - boolean lengthWritten = false; if (buf == null) buf = new byte[512]; @@ -472,14 +530,6 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput buf[pos++] = (byte) (0x80 | (0x3f & c)); } } - if (! lengthWritten) - { - if (i == len) - writeShort(pos); - else - writeShort(getUTFlength(value, i, pos)); - lengthWritten = true; - } write(buf, 0, pos); pos = 0; } -- cgit v1.2.3