mirror of
https://github.com/corda/corda.git
synced 2025-01-08 14:03:06 +00:00
Added AbstractMap for protobuf, and String getByte encoding for Latin-1
This commit is contained in:
parent
3d7c65d314
commit
10183a9870
26
classpath/avian/Iso88591.java
Normal file
26
classpath/avian/Iso88591.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
/* Copyright (c) 2011, 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 avian;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
|
public class Iso88591 {
|
||||||
|
|
||||||
|
public static byte[] encode(char[] s16, int offset, int length) {
|
||||||
|
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
||||||
|
for (int i = offset; i < offset+length; ++i) {
|
||||||
|
// ISO-88591-1/Latin-1 is the same as UTF-16 under 0x100
|
||||||
|
buf.write(s16[i]);
|
||||||
|
}
|
||||||
|
return buf.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
@ -16,10 +16,16 @@ import java.util.Comparator;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import avian.Utf8;
|
import avian.Utf8;
|
||||||
|
import avian.Iso88591;
|
||||||
|
|
||||||
public final class String
|
public final class String
|
||||||
implements Comparable<String>, CharSequence, Serializable
|
implements Comparable<String>, CharSequence, Serializable
|
||||||
{
|
{
|
||||||
|
private static final String UTF_8_ENCODING = "UTF-8";
|
||||||
|
private static final String ISO_8859_1_ENCODING = "ISO-8859-1";
|
||||||
|
private static final String LATIN_1_ENCODING = "LATIN-1";
|
||||||
|
private static final String DEFAULT_ENCODING = UTF_8_ENCODING;
|
||||||
|
|
||||||
public static Comparator<String> CASE_INSENSITIVE_ORDER
|
public static Comparator<String> CASE_INSENSITIVE_ORDER
|
||||||
= new Comparator<String>() {
|
= new Comparator<String>() {
|
||||||
public int compare(String a, String b) {
|
public int compare(String a, String b) {
|
||||||
@ -52,8 +58,8 @@ public final class String
|
|||||||
throws UnsupportedEncodingException
|
throws UnsupportedEncodingException
|
||||||
{
|
{
|
||||||
this(bytes, offset, length);
|
this(bytes, offset, length);
|
||||||
if (! (charsetName.equalsIgnoreCase("UTF-8")
|
if (! (charsetName.equalsIgnoreCase(UTF_8_ENCODING)
|
||||||
|| charsetName.equalsIgnoreCase("ISO-8859-1")))
|
|| charsetName.equalsIgnoreCase(ISO_8859_1_ENCODING)))
|
||||||
{
|
{
|
||||||
throw new UnsupportedEncodingException(charsetName);
|
throw new UnsupportedEncodingException(charsetName);
|
||||||
}
|
}
|
||||||
@ -421,18 +427,31 @@ public final class String
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes() {
|
public byte[] getBytes() {
|
||||||
if(data instanceof byte[]) {
|
try {
|
||||||
byte[] b = new byte[length];
|
return getBytes(DEFAULT_ENCODING);
|
||||||
getBytes(0, length, b, 0);
|
} catch (java.io.UnsupportedEncodingException ex) {
|
||||||
return b;
|
throw new RuntimeException(
|
||||||
|
"Default '" + DEFAULT_ENCODING + "' encoding not handled", ex);
|
||||||
}
|
}
|
||||||
return Utf8.encode((char[])data, offset, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes(String format)
|
public byte[] getBytes(String format)
|
||||||
throws java.io.UnsupportedEncodingException
|
throws java.io.UnsupportedEncodingException
|
||||||
{
|
{
|
||||||
return getBytes();
|
if(data instanceof byte[]) {
|
||||||
|
byte[] b = new byte[length];
|
||||||
|
getBytes(0, length, b, 0);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
String fmt = format.trim().toUpperCase();
|
||||||
|
if (DEFAULT_ENCODING.equals(fmt)) {
|
||||||
|
return Utf8.encode((char[])data, offset, length);
|
||||||
|
} else if (ISO_8859_1_ENCODING.equals(fmt) || LATIN_1_ENCODING.equals(fmt)) {
|
||||||
|
return Iso88591.encode((char[])data, offset, length);
|
||||||
|
} else {
|
||||||
|
throw new java.io.UnsupportedEncodingException(
|
||||||
|
"Encoding " + format + " not supported");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getChars(int srcOffset, int srcEnd,
|
public void getChars(int srcOffset, int srcEnd,
|
||||||
|
13
classpath/java/util/AbstractMap.java
Normal file
13
classpath/java/util/AbstractMap.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/* Copyright (c) 2008-2011, 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.util;
|
||||||
|
|
||||||
|
public abstract class AbstractMap<K,V> extends Object implements Map<K,V> { }
|
Loading…
Reference in New Issue
Block a user