summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-19 13:53:55 (EDT)
committerEike Stepper2007-09-19 13:53:55 (EDT)
commitc1e9dda6d64f132a9544b2eda7c583decf44367e (patch)
tree0afea589c6660246d7627b38cd5cb0b8aca0a6d3
parenta7419ab6a610ecdc1ff54670eb6f193c8ffec01c (diff)
downloadcdo-c1e9dda6d64f132a9544b2eda7c583decf44367e.zip
cdo-c1e9dda6d64f132a9544b2eda7c583decf44367e.tar.gz
cdo-c1e9dda6d64f132a9544b2eda7c583decf44367e.tar.bz2
[203866] Support UTF string
https://bugs.eclipse.org/bugs/show_bug.cgi?id=203866
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java40
1 files changed, 32 insertions, 8 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java
index 8c2077f..cfc5d90 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java
@@ -19,6 +19,14 @@ import java.io.IOException;
*/
public final class ExtendedIOUtil
{
+ private static final int UTF_HEADER_SIZE = 2;
+
+ private static final int MAX_16_BIT = (1 << 16) - 1;
+
+ private static final int MAX_UTF_LENGTH = MAX_16_BIT - UTF_HEADER_SIZE;
+
+ private static final int MAX_UTF_CHARS = MAX_UTF_LENGTH / 3;
+
private ExtendedIOUtil()
{
}
@@ -40,12 +48,20 @@ public final class ExtendedIOUtil
{
if (str != null)
{
- writeByteArray(out, str.getBytes());
- }
- else
- {
- out.writeInt(-1);
+ int size = str.length();
+ int start = 0;
+ do
+ {
+ out.writeBoolean(true);
+ int chunk = Math.min(size, MAX_UTF_CHARS);
+ int end = start + chunk;
+ out.writeUTF(str.substring(start, end));
+ start = end;
+ size -= chunk;
+ } while (size > 0);
}
+
+ out.writeBoolean(false);
}
public static byte[] readByteArray(DataInput in) throws IOException
@@ -72,12 +88,20 @@ public final class ExtendedIOUtil
public static String readString(DataInput in) throws IOException
{
- byte[] bytes = readByteArray(in);
- if (bytes == null)
+ boolean more = in.readBoolean();
+ if (!more)
{
return null;
}
- return new String(bytes);
+ StringBuilder builder = new StringBuilder();
+ do
+ {
+ String chunk = in.readUTF();
+ builder.append(chunk);
+ more = in.readBoolean();
+ } while (more);
+
+ return builder.toString();
}
}