feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,244 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class BASE64EncodingAlgorithm extends BuiltInEncodingAlgorithm {
/* package */ static final char encodeBase64[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};
/* package */ static final int decodeBase64[] = {
/*'+'*/ 62,
-1, -1, -1,
/*'/'*/ 63,
/*'0'*/ 52,
/*'1'*/ 53,
/*'2'*/ 54,
/*'3'*/ 55,
/*'4'*/ 56,
/*'5'*/ 57,
/*'6'*/ 58,
/*'7'*/ 59,
/*'8'*/ 60,
/*'9'*/ 61,
-1, -1, -1, -1, -1, -1, -1,
/*'A'*/ 0,
/*'B'*/ 1,
/*'C'*/ 2,
/*'D'*/ 3,
/*'E'*/ 4,
/*'F'*/ 5,
/*'G'*/ 6,
/*'H'*/ 7,
/*'I'*/ 8,
/*'J'*/ 9,
/*'K'*/ 10,
/*'L'*/ 11,
/*'M'*/ 12,
/*'N'*/ 13,
/*'O'*/ 14,
/*'P'*/ 15,
/*'Q'*/ 16,
/*'R'*/ 17,
/*'S'*/ 18,
/*'T'*/ 19,
/*'U'*/ 20,
/*'V'*/ 21,
/*'W'*/ 22,
/*'X'*/ 23,
/*'Y'*/ 24,
/*'Z'*/ 25,
-1, -1, -1, -1, -1, -1,
/*'a'*/ 26,
/*'b'*/ 27,
/*'c'*/ 28,
/*'d'*/ 29,
/*'e'*/ 30,
/*'f'*/ 31,
/*'g'*/ 32,
/*'h'*/ 33,
/*'i'*/ 34,
/*'j'*/ 35,
/*'k'*/ 36,
/*'l'*/ 37,
/*'m'*/ 38,
/*'n'*/ 39,
/*'o'*/ 40,
/*'p'*/ 41,
/*'q'*/ 42,
/*'r'*/ 43,
/*'s'*/ 44,
/*'t'*/ 45,
/*'u'*/ 46,
/*'v'*/ 47,
/*'w'*/ 48,
/*'x'*/ 49,
/*'y'*/ 50,
/*'z'*/ 51
};
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
final byte[] data = new byte[length];
System.arraycopy(b, start, data, 0, length);
return data;
}
public final Object decodeFromInputStream(InputStream s) throws IOException {
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
}
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
if (!(data instanceof byte[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotByteArray"));
}
s.write((byte[])data);
}
public final Object convertFromCharacters(char[] ch, int start, int length) {
if (length == 0) {
return new byte[0];
}
StringBuilder encodedValue = removeWhitespace(ch, start, length);
int encodedLength = encodedValue.length();
if (encodedLength == 0) {
return new byte[0];
}
int blockCount = encodedLength / 4;
int partialBlockLength = 3;
if (encodedValue.charAt(encodedLength - 1) == '=') {
--partialBlockLength;
if (encodedValue.charAt(encodedLength - 2) == '=') {
--partialBlockLength;
}
}
int valueLength = (blockCount - 1) * 3 + partialBlockLength;
byte[] value = new byte[valueLength];
int idx = 0;
int encodedIdx = 0;
for (int i = 0; i < blockCount; ++i) {
int x1 = decodeBase64[encodedValue.charAt(encodedIdx++) - '+'];
int x2 = decodeBase64[encodedValue.charAt(encodedIdx++) - '+'];
int x3 = decodeBase64[encodedValue.charAt(encodedIdx++) - '+'];
int x4 = decodeBase64[encodedValue.charAt(encodedIdx++) - '+'];
value[idx++] = (byte) ((x1 << 2) | (x2 >> 4));
if (idx < valueLength) {
value[idx++] = (byte) (((x2 & 0x0f) << 4) | (x3 >> 2));
}
if (idx < valueLength) {
value[idx++] = (byte) (((x3 & 0x03) << 6) | x4);
}
}
return value;
}
public final void convertToCharacters(Object data, StringBuffer s) {
if (data == null) {
return;
}
final byte[] value = (byte[]) data;
convertToCharacters(value, 0, value.length, s);
}
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
return octetLength;
}
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
return primitiveLength;
}
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
System.arraycopy((byte[])array, astart, b, start, alength);
}
public final void convertToCharacters(byte[] data, int offset, int length, StringBuffer s) {
if (data == null) {
return;
}
final byte[] value = data;
if (length == 0) {
return;
}
final int partialBlockLength = length % 3;
final int blockCount = (partialBlockLength != 0) ?
length / 3 + 1 :
length / 3;
final int encodedLength = blockCount * 4;
final int originalBufferSize = s.length();
s.ensureCapacity(encodedLength + originalBufferSize);
int idx = offset;
int lastIdx = offset + length;
for (int i = 0; i < blockCount; ++i) {
int b1 = value[idx++] & 0xFF;
int b2 = (idx < lastIdx) ? value[idx++] & 0xFF : 0;
int b3 = (idx < lastIdx) ? value[idx++] & 0xFF : 0;
s.append(encodeBase64[b1 >> 2]);
s.append(encodeBase64[((b1 & 0x03) << 4) | (b2 >> 4)]);
s.append(encodeBase64[((b2 & 0x0f) << 2) | (b3 >> 6)]);
s.append(encodeBase64[b3 & 0x3f]);
}
switch (partialBlockLength) {
case 1 :
s.setCharAt(originalBufferSize + encodedLength - 1, '=');
s.setCharAt(originalBufferSize + encodedLength - 2, '=');
break;
case 2 :
s.setCharAt(originalBufferSize + encodedLength - 1, '=');
break;
}
}
}

View File

@@ -0,0 +1,271 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
/**
*
* An encoder for handling boolean values. Suppports the builtin BOOLEAN encoder.
*
* @author Alan Hudson
* @author Paul Sandoz
*
*/
public class BooleanEncodingAlgorithm extends BuiltInEncodingAlgorithm {
/** Table for setting a particular bit of a byte */
private static final int[] BIT_TABLE = {
1 << 7,
1 << 6,
1 << 5,
1 << 4,
1 << 3,
1 << 2,
1 << 1,
1 << 0};
public int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
// Cannot determine the number of boolean values from just the octet length
throw new UnsupportedOperationException();
}
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
if (primitiveLength < 5) {
return 1;
} else {
final int div = primitiveLength / 8;
return (div == 0) ? 2 : 1 + div;
}
}
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
final int blength = getPrimtiveLengthFromOctetLength(length, b[start]);
boolean[] data = new boolean[blength];
decodeFromBytesToBooleanArray(data, 0, blength, b, start, length);
return data;
}
public final Object decodeFromInputStream(InputStream s) throws IOException {
final List booleanList = new ArrayList();
int value = s.read();
if (value == -1) {
throw new EOFException();
}
final int unusedBits = (value >> 4) & 0xFF;
int bitPosition = 4;
int bitPositionEnd = 8;
int valueNext = 0;
do {
valueNext = s.read();
if (valueNext == -1) {
bitPositionEnd -= unusedBits;
}
while(bitPosition < bitPositionEnd) {
booleanList.add(
Boolean.valueOf((value & BIT_TABLE[bitPosition++]) > 0));
}
value = valueNext;
} while (value != -1);
return generateArrayFromList(booleanList);
}
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
if (!(data instanceof boolean[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotBoolean"));
}
boolean array[] = (boolean[])data;
final int alength = array.length;
final int mod = (alength + 4) % 8;
final int unusedBits = (mod == 0) ? 0 : 8 - mod;
int bitPosition = 4;
int value = unusedBits << 4;
int astart = 0;
while (astart < alength) {
if (array[astart++]) {
value |= BIT_TABLE[bitPosition];
}
if (++bitPosition == 8) {
s.write(value);
bitPosition = value = 0;
}
}
if (bitPosition != 8) {
s.write(value);
}
}
public final Object convertFromCharacters(char[] ch, int start, int length) {
if (length == 0) {
return new boolean[0];
}
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
final List booleanList = new ArrayList();
matchWhiteSpaceDelimnatedWords(cb,
new WordListener() {
public void word(int start, int end) {
if (cb.charAt(start) == 't') {
booleanList.add(Boolean.TRUE);
} else {
booleanList.add(Boolean.FALSE);
}
}
}
);
return generateArrayFromList(booleanList);
}
public final void convertToCharacters(Object data, StringBuffer s) {
if (data == null) {
return;
}
final boolean[] value = (boolean[]) data;
if (value.length == 0) {
return;
}
// Insure conservately as all false
s.ensureCapacity(value.length * 5);
final int end = value.length - 1;
for (int i = 0; i <= end; i++) {
if (value[i]) {
s.append("true");
} else {
s.append("false");
}
if (i != end) {
s.append(' ');
}
}
}
public int getPrimtiveLengthFromOctetLength(int octetLength, int firstOctet) throws EncodingAlgorithmException {
final int unusedBits = (firstOctet >> 4) & 0xFF;
if (octetLength == 1) {
if (unusedBits > 3) {
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.unusedBits4"));
}
return 4 - unusedBits;
} else {
if (unusedBits > 7) {
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.unusedBits8"));
}
return octetLength * 8 - 4 - unusedBits;
}
}
public final void decodeFromBytesToBooleanArray(boolean[] bdata, int bstart, int blength, byte[] b, int start, int length) {
int value = b[start++] & 0xFF;
int bitPosition = 4;
final int bend = bstart + blength;
while (bstart < bend) {
if (bitPosition == 8) {
value = b[start++] & 0xFF;
bitPosition = 0;
}
bdata[bstart++] = (value & BIT_TABLE[bitPosition++]) > 0;
}
}
public void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
if (!(array instanceof boolean[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotBoolean"));
}
encodeToBytesFromBooleanArray((boolean[])array, astart, alength, b, start);
}
public void encodeToBytesFromBooleanArray(boolean[] array, int astart, int alength, byte[] b, int start) {
final int mod = (alength + 4) % 8;
final int unusedBits = (mod == 0) ? 0 : 8 - mod;
int bitPosition = 4;
int value = unusedBits << 4;
final int aend = astart + alength;
while (astart < aend) {
if (array[astart++]) {
value |= BIT_TABLE[bitPosition];
}
if (++bitPosition == 8) {
b[start++] = (byte)value;
bitPosition = value = 0;
}
}
if (bitPosition > 0) {
b[start] = (byte)value;
}
}
/**
*
* Generate a boolean array from a list of Booleans.
*
* @param array The array
*
*/
private boolean[] generateArrayFromList(List array) {
boolean[] bdata = new boolean[array.size()];
for (int i = 0; i < bdata.length; i++) {
bdata[i] = ((Boolean)array.get(i)).booleanValue();
}
return bdata;
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.nio.CharBuffer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
public abstract class BuiltInEncodingAlgorithm implements EncodingAlgorithm {
protected final static Pattern SPACE_PATTERN = Pattern.compile("\\s");
public abstract int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException;
public abstract int getOctetLengthFromPrimitiveLength(int primitiveLength);
public abstract void encodeToBytes(Object array, int astart, int alength, byte[] b, int start);
public interface WordListener {
public void word(int start, int end);
}
public void matchWhiteSpaceDelimnatedWords(CharBuffer cb, WordListener wl) {
Matcher m = SPACE_PATTERN.matcher(cb);
int i = 0;
int s = 0;
while(m.find()) {
s = m.start();
if (s != i) {
wl.word(i, s);
}
i = m.end();
}
if (i != cb.length())
wl.word(i, cb.length());
}
public StringBuilder removeWhitespace(char[] ch, int start, int length) {
StringBuilder buf = new StringBuilder();
int firstNonWS = 0;
int idx = 0;
for (; idx < length; ++idx) {
if (Character.isWhitespace(ch[idx + start])) {
if (firstNonWS < idx) {
buf.append(ch, firstNonWS + start, idx - firstNonWS);
}
firstNonWS = idx + 1;
}
}
if (firstNonWS < idx) {
buf.append(ch, firstNonWS + start, idx - firstNonWS);
}
return buf;
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import com.sun.xml.internal.fastinfoset.EncodingConstants;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
public final class BuiltInEncodingAlgorithmFactory {
private final static BuiltInEncodingAlgorithm[] table =
new BuiltInEncodingAlgorithm[EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END + 1];
public final static HexadecimalEncodingAlgorithm hexadecimalEncodingAlgorithm = new HexadecimalEncodingAlgorithm();
public final static BASE64EncodingAlgorithm base64EncodingAlgorithm = new BASE64EncodingAlgorithm();
public final static BooleanEncodingAlgorithm booleanEncodingAlgorithm = new BooleanEncodingAlgorithm();
public final static ShortEncodingAlgorithm shortEncodingAlgorithm = new ShortEncodingAlgorithm();
public final static IntEncodingAlgorithm intEncodingAlgorithm = new IntEncodingAlgorithm();
public final static LongEncodingAlgorithm longEncodingAlgorithm = new LongEncodingAlgorithm();
public final static FloatEncodingAlgorithm floatEncodingAlgorithm = new FloatEncodingAlgorithm();
public final static DoubleEncodingAlgorithm doubleEncodingAlgorithm = new DoubleEncodingAlgorithm();
public final static UUIDEncodingAlgorithm uuidEncodingAlgorithm = new UUIDEncodingAlgorithm();
static {
table[EncodingAlgorithmIndexes.HEXADECIMAL] = hexadecimalEncodingAlgorithm;
table[EncodingAlgorithmIndexes.BASE64] = base64EncodingAlgorithm;
table[EncodingAlgorithmIndexes.SHORT] = shortEncodingAlgorithm;
table[EncodingAlgorithmIndexes.INT] = intEncodingAlgorithm;
table[EncodingAlgorithmIndexes.LONG] = longEncodingAlgorithm;
table[EncodingAlgorithmIndexes.BOOLEAN] = booleanEncodingAlgorithm;
table[EncodingAlgorithmIndexes.FLOAT] = floatEncodingAlgorithm;
table[EncodingAlgorithmIndexes.DOUBLE] = doubleEncodingAlgorithm;
table[EncodingAlgorithmIndexes.UUID] = uuidEncodingAlgorithm;
}
public static BuiltInEncodingAlgorithm getAlgorithm(int index) {
return table[index];
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
public class BuiltInEncodingAlgorithmState {
public static final int INITIAL_LENGTH = 8;
public boolean[] booleanArray = new boolean[INITIAL_LENGTH];
public short[] shortArray = new short[INITIAL_LENGTH];
public int[] intArray = new int[INITIAL_LENGTH];
public long[] longArray = new long[INITIAL_LENGTH];
public float[] floatArray = new float[INITIAL_LENGTH];
public double[] doubleArray = new double[INITIAL_LENGTH];
}

View File

@@ -0,0 +1,213 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class DoubleEncodingAlgorithm extends IEEE754FloatingPointEncodingAlgorithm {
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
if (octetLength % DOUBLE_SIZE != 0) {
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
getString("message.lengthIsNotMultipleOfDouble", new Object[]{Integer.valueOf(DOUBLE_SIZE)}));
}
return octetLength / DOUBLE_SIZE;
}
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
return primitiveLength * DOUBLE_SIZE;
}
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
double[] data = new double[getPrimtiveLengthFromOctetLength(length)];
decodeFromBytesToDoubleArray(data, 0, b, start, length);
return data;
}
public final Object decodeFromInputStream(InputStream s) throws IOException {
return decodeFromInputStreamToDoubleArray(s);
}
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
if (!(data instanceof double[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotDouble"));
}
final double[] fdata = (double[])data;
encodeToOutputStreamFromDoubleArray(fdata, s);
}
public final Object convertFromCharacters(char[] ch, int start, int length) {
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
final List doubleList = new ArrayList();
matchWhiteSpaceDelimnatedWords(cb,
new WordListener() {
public void word(int start, int end) {
String fStringValue = cb.subSequence(start, end).toString();
doubleList.add(Double.valueOf(fStringValue));
}
}
);
return generateArrayFromList(doubleList);
}
public final void convertToCharacters(Object data, StringBuffer s) {
if (!(data instanceof double[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotDouble"));
}
final double[] fdata = (double[])data;
convertToCharactersFromDoubleArray(fdata, s);
}
public final void decodeFromBytesToDoubleArray(double[] data, int fstart, byte[] b, int start, int length) {
final int size = length / DOUBLE_SIZE;
for (int i = 0; i < size; i++) {
final long bits =
((long)(b[start++] & 0xFF) << 56) |
((long)(b[start++] & 0xFF) << 48) |
((long)(b[start++] & 0xFF) << 40) |
((long)(b[start++] & 0xFF) << 32) |
((long)(b[start++] & 0xFF) << 24) |
((long)(b[start++] & 0xFF) << 16) |
((long)(b[start++] & 0xFF) << 8) |
(long)(b[start++] & 0xFF);
data[fstart++] = Double.longBitsToDouble(bits);
}
}
public final double[] decodeFromInputStreamToDoubleArray(InputStream s) throws IOException {
final List doubleList = new ArrayList();
final byte[] b = new byte[DOUBLE_SIZE];
while (true) {
int n = s.read(b);
if (n != DOUBLE_SIZE) {
if (n == -1) {
break;
}
while(n != DOUBLE_SIZE) {
final int m = s.read(b, n, DOUBLE_SIZE - n);
if (m == -1) {
throw new EOFException();
}
n += m;
}
}
final long bits =
((long)(b[0] & 0xFF) << 56) |
((long)(b[1] & 0xFF) << 48) |
((long)(b[2] & 0xFF) << 40) |
((long)(b[3] & 0xFF) << 32) |
((b[4] & 0xFF) << 24) |
((b[5] & 0xFF) << 16) |
((b[6] & 0xFF) << 8) |
(b[7] & 0xFF);
doubleList.add(Double.valueOf(Double.longBitsToDouble(bits)));
}
return generateArrayFromList(doubleList);
}
public final void encodeToOutputStreamFromDoubleArray(double[] fdata, OutputStream s) throws IOException {
for (int i = 0; i < fdata.length; i++) {
final long bits = Double.doubleToLongBits(fdata[i]);
s.write((int)((bits >>> 56) & 0xFF));
s.write((int)((bits >>> 48) & 0xFF));
s.write((int)((bits >>> 40) & 0xFF));
s.write((int)((bits >>> 32) & 0xFF));
s.write((int)((bits >>> 24) & 0xFF));
s.write((int)((bits >>> 16) & 0xFF));
s.write((int)((bits >>> 8) & 0xFF));
s.write((int)(bits & 0xFF));
}
}
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
encodeToBytesFromDoubleArray((double[])array, astart, alength, b, start);
}
public final void encodeToBytesFromDoubleArray(double[] fdata, int fstart, int flength, byte[] b, int start) {
final int fend = fstart + flength;
for (int i = fstart; i < fend; i++) {
final long bits = Double.doubleToLongBits(fdata[i]);
b[start++] = (byte)((bits >>> 56) & 0xFF);
b[start++] = (byte)((bits >>> 48) & 0xFF);
b[start++] = (byte)((bits >>> 40) & 0xFF);
b[start++] = (byte)((bits >>> 32) & 0xFF);
b[start++] = (byte)((bits >>> 24) & 0xFF);
b[start++] = (byte)((bits >>> 16) & 0xFF);
b[start++] = (byte)((bits >>> 8) & 0xFF);
b[start++] = (byte)(bits & 0xFF);
}
}
public final void convertToCharactersFromDoubleArray(double[] fdata, StringBuffer s) {
final int end = fdata.length - 1;
for (int i = 0; i <= end; i++) {
s.append(Double.toString(fdata[i]));
if (i != end) {
s.append(' ');
}
}
}
public final double[] generateArrayFromList(List array) {
double[] fdata = new double[array.size()];
for (int i = 0; i < fdata.length; i++) {
fdata[i] = ((Double)array.get(i)).doubleValue();
}
return fdata;
}
}

View File

@@ -0,0 +1,194 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class FloatEncodingAlgorithm extends IEEE754FloatingPointEncodingAlgorithm {
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
if (octetLength % FLOAT_SIZE != 0) {
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
getString("message.lengthNotMultipleOfFloat", new Object[]{Integer.valueOf(FLOAT_SIZE)}));
}
return octetLength / FLOAT_SIZE;
}
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
return primitiveLength * FLOAT_SIZE;
}
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
float[] data = new float[getPrimtiveLengthFromOctetLength(length)];
decodeFromBytesToFloatArray(data, 0, b, start, length);
return data;
}
public final Object decodeFromInputStream(InputStream s) throws IOException {
return decodeFromInputStreamToFloatArray(s);
}
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
if (!(data instanceof float[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotFloat"));
}
final float[] fdata = (float[])data;
encodeToOutputStreamFromFloatArray(fdata, s);
}
public final Object convertFromCharacters(char[] ch, int start, int length) {
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
final List floatList = new ArrayList();
matchWhiteSpaceDelimnatedWords(cb,
new WordListener() {
public void word(int start, int end) {
String fStringValue = cb.subSequence(start, end).toString();
floatList.add(Float.valueOf(fStringValue));
}
}
);
return generateArrayFromList(floatList);
}
public final void convertToCharacters(Object data, StringBuffer s) {
if (!(data instanceof float[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotFloat"));
}
final float[] fdata = (float[])data;
convertToCharactersFromFloatArray(fdata, s);
}
public final void decodeFromBytesToFloatArray(float[] data, int fstart, byte[] b, int start, int length) {
final int size = length / FLOAT_SIZE;
for (int i = 0; i < size; i++) {
final int bits = ((b[start++] & 0xFF) << 24) |
((b[start++] & 0xFF) << 16) |
((b[start++] & 0xFF) << 8) |
(b[start++] & 0xFF);
data[fstart++] = Float.intBitsToFloat(bits);
}
}
public final float[] decodeFromInputStreamToFloatArray(InputStream s) throws IOException {
final List floatList = new ArrayList();
final byte[] b = new byte[FLOAT_SIZE];
while (true) {
int n = s.read(b);
if (n != 4) {
if (n == -1) {
break;
}
while(n != 4) {
final int m = s.read(b, n, FLOAT_SIZE - n);
if (m == -1) {
throw new EOFException();
}
n += m;
}
}
final int bits = ((b[0] & 0xFF) << 24) |
((b[1] & 0xFF) << 16) |
((b[2] & 0xFF) << 8) |
(b[3] & 0xFF);
floatList.add(Float.valueOf(Float.intBitsToFloat(bits)));
}
return generateArrayFromList(floatList);
}
public final void encodeToOutputStreamFromFloatArray(float[] fdata, OutputStream s) throws IOException {
for (int i = 0; i < fdata.length; i++) {
final int bits = Float.floatToIntBits(fdata[i]);
s.write((bits >>> 24) & 0xFF);
s.write((bits >>> 16) & 0xFF);
s.write((bits >>> 8) & 0xFF);
s.write(bits & 0xFF);
}
}
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
encodeToBytesFromFloatArray((float[])array, astart, alength, b, start);
}
public final void encodeToBytesFromFloatArray(float[] fdata, int fstart, int flength, byte[] b, int start) {
final int fend = fstart + flength;
for (int i = fstart; i < fend; i++) {
final int bits = Float.floatToIntBits(fdata[i]);
b[start++] = (byte)((bits >>> 24) & 0xFF);
b[start++] = (byte)((bits >>> 16) & 0xFF);
b[start++] = (byte)((bits >>> 8) & 0xFF);
b[start++] = (byte)(bits & 0xFF);
}
}
public final void convertToCharactersFromFloatArray(float[] fdata, StringBuffer s) {
final int end = fdata.length - 1;
for (int i = 0; i <= end; i++) {
s.append(Float.toString(fdata[i]));
if (i != end) {
s.append(' ');
}
}
}
public final float[] generateArrayFromList(List array) {
float[] fdata = new float[array.size()];
for (int i = 0; i < fdata.length; i++) {
fdata[i] = ((Float)array.get(i)).floatValue();
}
return fdata;
}
}

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class HexadecimalEncodingAlgorithm extends BuiltInEncodingAlgorithm {
private static final char NIBBLE_TO_HEXADECIMAL_TABLE[] =
{ '0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F' };
private static final int HEXADECIMAL_TO_NIBBLE_TABLE[] = {
/*'0'*/ 0,
/*'1'*/ 1,
/*'2'*/ 2,
/*'3'*/ 3,
/*'4'*/ 4,
/*'5'*/ 5,
/*'6'*/ 6,
/*'7'*/ 7,
/*'8'*/ 8,
/*'9'*/ 9, -1, -1, -1, -1, -1, -1, -1,
/*'A'*/ 10,
/*'B'*/ 11,
/*'C'*/ 12,
/*'D'*/ 13,
/*'E'*/ 14,
/*'F'*/ 15,
/*'G'-'Z'*/-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/*'[' - '`'*/ -1, -1, -1, -1, -1, -1,
/*'a'*/ 10,
/*'b'*/ 11,
/*'c'*/ 12,
/*'d'*/ 13,
/*'e'*/ 14,
/*'f'*/ 15 };
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
final byte[] data = new byte[length];
System.arraycopy(b, start, data, 0, length);
return data;
}
public final Object decodeFromInputStream(InputStream s) throws IOException {
throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
}
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
if (!(data instanceof byte[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotByteArray"));
}
s.write((byte[])data);
}
public final Object convertFromCharacters(char[] ch, int start, int length) {
if (length == 0) {
return new byte[0];
}
StringBuilder encodedValue = removeWhitespace(ch, start, length);
int encodedLength = encodedValue.length();
if (encodedLength == 0) {
return new byte[0];
}
int valueLength = encodedValue.length() / 2;
byte[] value = new byte[valueLength];
int encodedIdx = 0;
for (int i = 0; i < valueLength; ++i) {
int nibble1 = HEXADECIMAL_TO_NIBBLE_TABLE[encodedValue.charAt(encodedIdx++) - '0'];
int nibble2 = HEXADECIMAL_TO_NIBBLE_TABLE[encodedValue.charAt(encodedIdx++) - '0'];
value[i] = (byte) ((nibble1 << 4) | nibble2);
}
return value;
}
public final void convertToCharacters(Object data, StringBuffer s) {
if (data == null) {
return;
}
final byte[] value = (byte[]) data;
if (value.length == 0) {
return;
}
s.ensureCapacity(value.length * 2);
for (int i = 0; i < value.length; ++i) {
s.append(NIBBLE_TO_HEXADECIMAL_TABLE[(value[i] >>> 4) & 0xf]);
s.append(NIBBLE_TO_HEXADECIMAL_TABLE[value[i] & 0xf]);
}
}
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
return octetLength * 2;
}
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
return primitiveLength / 2;
}
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
System.arraycopy((byte[])array, astart, b, start, alength);
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
public abstract class IEEE754FloatingPointEncodingAlgorithm extends BuiltInEncodingAlgorithm {
public final static int FLOAT_SIZE = 4;
public final static int DOUBLE_SIZE = 8;
public final static int FLOAT_MAX_CHARACTER_SIZE = 14;
public final static int DOUBLE_MAX_CHARACTER_SIZE = 24;
}

View File

@@ -0,0 +1,193 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class IntEncodingAlgorithm extends IntegerEncodingAlgorithm {
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
if (octetLength % INT_SIZE != 0) {
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
getString("message.lengthNotMultipleOfInt", new Object[]{Integer.valueOf(INT_SIZE)}));
}
return octetLength / INT_SIZE;
}
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
return primitiveLength * INT_SIZE;
}
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
int[] data = new int[getPrimtiveLengthFromOctetLength(length)];
decodeFromBytesToIntArray(data, 0, b, start, length);
return data;
}
public final Object decodeFromInputStream(InputStream s) throws IOException {
return decodeFromInputStreamToIntArray(s);
}
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
if (!(data instanceof int[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotIntArray"));
}
final int[] idata = (int[])data;
encodeToOutputStreamFromIntArray(idata, s);
}
public final Object convertFromCharacters(char[] ch, int start, int length) {
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
final List integerList = new ArrayList();
matchWhiteSpaceDelimnatedWords(cb,
new WordListener() {
public void word(int start, int end) {
String iStringValue = cb.subSequence(start, end).toString();
integerList.add(Integer.valueOf(iStringValue));
}
}
);
return generateArrayFromList(integerList);
}
public final void convertToCharacters(Object data, StringBuffer s) {
if (!(data instanceof int[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotIntArray"));
}
final int[] idata = (int[])data;
convertToCharactersFromIntArray(idata, s);
}
public final void decodeFromBytesToIntArray(int[] idata, int istart, byte[] b, int start, int length) {
final int size = length / INT_SIZE;
for (int i = 0; i < size; i++) {
idata[istart++] = ((b[start++] & 0xFF) << 24) |
((b[start++] & 0xFF) << 16) |
((b[start++] & 0xFF) << 8) |
(b[start++] & 0xFF);
}
}
public final int[] decodeFromInputStreamToIntArray(InputStream s) throws IOException {
final List integerList = new ArrayList();
final byte[] b = new byte[INT_SIZE];
while (true) {
int n = s.read(b);
if (n != 4) {
if (n == -1) {
break;
}
while(n != 4) {
final int m = s.read(b, n, INT_SIZE - n);
if (m == -1) {
throw new EOFException();
}
n += m;
}
}
final int i = ((b[0] & 0xFF) << 24) |
((b[1] & 0xFF) << 16) |
((b[2] & 0xFF) << 8) |
(b[3] & 0xFF);
integerList.add(Integer.valueOf(i));
}
return generateArrayFromList(integerList);
}
public final void encodeToOutputStreamFromIntArray(int[] idata, OutputStream s) throws IOException {
for (int i = 0; i < idata.length; i++) {
final int bits = idata[i];
s.write((bits >>> 24) & 0xFF);
s.write((bits >>> 16) & 0xFF);
s.write((bits >>> 8) & 0xFF);
s.write(bits & 0xFF);
}
}
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
encodeToBytesFromIntArray((int[])array, astart, alength, b, start);
}
public final void encodeToBytesFromIntArray(int[] idata, int istart, int ilength, byte[] b, int start) {
final int iend = istart + ilength;
for (int i = istart; i < iend; i++) {
final int bits = idata[i];
b[start++] = (byte)((bits >>> 24) & 0xFF);
b[start++] = (byte)((bits >>> 16) & 0xFF);
b[start++] = (byte)((bits >>> 8) & 0xFF);
b[start++] = (byte)(bits & 0xFF);
}
}
public final void convertToCharactersFromIntArray(int[] idata, StringBuffer s) {
final int end = idata.length - 1;
for (int i = 0; i <= end; i++) {
s.append(Integer.toString(idata[i]));
if (i != end) {
s.append(' ');
}
}
}
public final int[] generateArrayFromList(List array) {
int[] idata = new int[array.size()];
for (int i = 0; i < idata.length; i++) {
idata[i] = ((Integer)array.get(i)).intValue();
}
return idata;
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
public abstract class IntegerEncodingAlgorithm extends BuiltInEncodingAlgorithm {
public final static int SHORT_SIZE = 2;
public final static int INT_SIZE = 4;
public final static int LONG_SIZE = 8;
public final static int SHORT_MAX_CHARACTER_SIZE = 6;
public final static int INT_MAX_CHARACTER_SIZE = 11;
public final static int LONG_MAX_CHARACTER_SIZE = 20;
}

View File

@@ -0,0 +1,211 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class LongEncodingAlgorithm extends IntegerEncodingAlgorithm {
public int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
if (octetLength % LONG_SIZE != 0) {
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
getString("message.lengthNotMultipleOfLong", new Object[]{Integer.valueOf(LONG_SIZE)}));
}
return octetLength / LONG_SIZE;
}
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
return primitiveLength * LONG_SIZE;
}
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
long[] data = new long[getPrimtiveLengthFromOctetLength(length)];
decodeFromBytesToLongArray(data, 0, b, start, length);
return data;
}
public final Object decodeFromInputStream(InputStream s) throws IOException {
return decodeFromInputStreamToIntArray(s);
}
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
if (!(data instanceof long[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotLongArray"));
}
final long[] ldata = (long[])data;
encodeToOutputStreamFromLongArray(ldata, s);
}
public Object convertFromCharacters(char[] ch, int start, int length) {
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
final List longList = new ArrayList();
matchWhiteSpaceDelimnatedWords(cb,
new WordListener() {
public void word(int start, int end) {
String lStringValue = cb.subSequence(start, end).toString();
longList.add(Long.valueOf(lStringValue));
}
}
);
return generateArrayFromList(longList);
}
public void convertToCharacters(Object data, StringBuffer s) {
if (!(data instanceof long[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotLongArray"));
}
final long[] ldata = (long[])data;
convertToCharactersFromLongArray(ldata, s);
}
public final void decodeFromBytesToLongArray(long[] ldata, int istart, byte[] b, int start, int length) {
final int size = length / LONG_SIZE;
for (int i = 0; i < size; i++) {
ldata[istart++] =
((long)(b[start++] & 0xFF) << 56) |
((long)(b[start++] & 0xFF) << 48) |
((long)(b[start++] & 0xFF) << 40) |
((long)(b[start++] & 0xFF) << 32) |
((long)(b[start++] & 0xFF) << 24) |
((long)(b[start++] & 0xFF) << 16) |
((long)(b[start++] & 0xFF) << 8) |
(long)(b[start++] & 0xFF);
}
}
public final long[] decodeFromInputStreamToIntArray(InputStream s) throws IOException {
final List longList = new ArrayList();
final byte[] b = new byte[LONG_SIZE];
while (true) {
int n = s.read(b);
if (n != LONG_SIZE) {
if (n == -1) {
break;
}
while(n != LONG_SIZE) {
final int m = s.read(b, n, LONG_SIZE - n);
if (m == -1) {
throw new EOFException();
}
n += m;
}
}
final long l =
(((long) b[0] << 56) +
((long) (b[1] & 0xFF) << 48) +
((long) (b[2] & 0xFF) << 40) +
((long) (b[3] & 0xFF) << 32) +
((long) (b[4] & 0xFF) << 24) +
((b[5] & 0xFF) << 16) +
((b[6] & 0xFF) << 8) +
((b[7] & 0xFF) << 0));
longList.add(Long.valueOf(l));
}
return generateArrayFromList(longList);
}
public final void encodeToOutputStreamFromLongArray(long[] ldata, OutputStream s) throws IOException {
for (int i = 0; i < ldata.length; i++) {
final long bits = ldata[i];
s.write((int)((bits >>> 56) & 0xFF));
s.write((int)((bits >>> 48) & 0xFF));
s.write((int)((bits >>> 40) & 0xFF));
s.write((int)((bits >>> 32) & 0xFF));
s.write((int)((bits >>> 24) & 0xFF));
s.write((int)((bits >>> 16) & 0xFF));
s.write((int)((bits >>> 8) & 0xFF));
s.write((int)(bits & 0xFF));
}
}
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
encodeToBytesFromLongArray((long[])array, astart, alength, b, start);
}
public final void encodeToBytesFromLongArray(long[] ldata, int lstart, int llength, byte[] b, int start) {
final int lend = lstart + llength;
for (int i = lstart; i < lend; i++) {
final long bits = ldata[i];
b[start++] = (byte)((bits >>> 56) & 0xFF);
b[start++] = (byte)((bits >>> 48) & 0xFF);
b[start++] = (byte)((bits >>> 40) & 0xFF);
b[start++] = (byte)((bits >>> 32) & 0xFF);
b[start++] = (byte)((bits >>> 24) & 0xFF);
b[start++] = (byte)((bits >>> 16) & 0xFF);
b[start++] = (byte)((bits >>> 8) & 0xFF);
b[start++] = (byte)(bits & 0xFF);
}
}
public final void convertToCharactersFromLongArray(long[] ldata, StringBuffer s) {
final int end = ldata.length - 1;
for (int i = 0; i <= end; i++) {
s.append(Long.toString(ldata[i]));
if (i != end) {
s.append(' ');
}
}
}
public final long[] generateArrayFromList(List array) {
long[] ldata = new long[array.size()];
for (int i = 0; i < ldata.length; i++) {
ldata[i] = ((Long)array.get(i)).longValue();
}
return ldata;
}
}

View File

@@ -0,0 +1,190 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
/**
* An encoder for handling Short values. Suppports the builtin SHORT encoder.
*
* @author Alan Hudson
* @author Paul Sandoz
*/
public class ShortEncodingAlgorithm extends IntegerEncodingAlgorithm {
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
if (octetLength % SHORT_SIZE != 0) {
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
getString("message.lengthNotMultipleOfShort", new Object[]{Integer.valueOf(SHORT_SIZE)}));
}
return octetLength / SHORT_SIZE;
}
public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
return primitiveLength * SHORT_SIZE;
}
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
short[] data = new short[getPrimtiveLengthFromOctetLength(length)];
decodeFromBytesToShortArray(data, 0, b, start, length);
return data;
}
public final Object decodeFromInputStream(InputStream s) throws IOException {
return decodeFromInputStreamToShortArray(s);
}
public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
if (!(data instanceof short[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotShortArray"));
}
final short[] idata = (short[])data;
encodeToOutputStreamFromShortArray(idata, s);
}
public final Object convertFromCharacters(char[] ch, int start, int length) {
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
final List shortList = new ArrayList();
matchWhiteSpaceDelimnatedWords(cb,
new WordListener() {
public void word(int start, int end) {
String iStringValue = cb.subSequence(start, end).toString();
shortList.add(Short.valueOf(iStringValue));
}
}
);
return generateArrayFromList(shortList);
}
public final void convertToCharacters(Object data, StringBuffer s) {
if (!(data instanceof short[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotShortArray"));
}
final short[] idata = (short[])data;
convertToCharactersFromShortArray(idata, s);
}
public final void decodeFromBytesToShortArray(short[] sdata, int istart, byte[] b, int start, int length) {
final int size = length / SHORT_SIZE;
for (int i = 0; i < size; i++) {
sdata[istart++] = (short) (((b[start++] & 0xFF) << 8) |
(b[start++] & 0xFF));
}
}
public final short[] decodeFromInputStreamToShortArray(InputStream s) throws IOException {
final List shortList = new ArrayList();
final byte[] b = new byte[SHORT_SIZE];
while (true) {
int n = s.read(b);
if (n != 2) {
if (n == -1) {
break;
}
while(n != 2) {
final int m = s.read(b, n, SHORT_SIZE - n);
if (m == -1) {
throw new EOFException();
}
n += m;
}
}
final int i = ((b[0] & 0xFF) << 8) |
(b[1] & 0xFF);
shortList.add(Short.valueOf((short)i));
}
return generateArrayFromList(shortList);
}
public final void encodeToOutputStreamFromShortArray(short[] idata, OutputStream s) throws IOException {
for (int i = 0; i < idata.length; i++) {
final int bits = idata[i];
s.write((bits >>> 8) & 0xFF);
s.write(bits & 0xFF);
}
}
public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
encodeToBytesFromShortArray((short[])array, astart, alength, b, start);
}
public final void encodeToBytesFromShortArray(short[] sdata, int istart, int ilength, byte[] b, int start) {
final int iend = istart + ilength;
for (int i = istart; i < iend; i++) {
final short bits = sdata[i];
b[start++] = (byte)((bits >>> 8) & 0xFF);
b[start++] = (byte)(bits & 0xFF);
}
}
public final void convertToCharactersFromShortArray(short[] sdata, StringBuffer s) {
final int end = sdata.length - 1;
for (int i = 0; i <= end; i++) {
s.append(Short.toString(sdata[i]));
if (i != end) {
s.append(' ');
}
}
}
public final short[] generateArrayFromList(List array) {
short[] sdata = new short[array.size()];
for (int i = 0; i < sdata.length; i++) {
sdata[i] = ((Short)array.get(i)).shortValue();
}
return sdata;
}
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
*/
package com.sun.xml.internal.fastinfoset.algorithm;
import java.util.ArrayList;
import java.util.List;
import java.nio.CharBuffer;
import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
public class UUIDEncodingAlgorithm extends LongEncodingAlgorithm {
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
if (octetLength % (LONG_SIZE * 2) != 0) {
throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
getString("message.lengthNotMultipleOfUUID",new Object[]{Integer.valueOf(LONG_SIZE * 2)}));
}
return octetLength / LONG_SIZE;
}
public final Object convertFromCharacters(char[] ch, int start, int length) {
final CharBuffer cb = CharBuffer.wrap(ch, start, length);
final List longList = new ArrayList();
matchWhiteSpaceDelimnatedWords(cb,
new WordListener() {
public void word(int start, int end) {
String uuidValue = cb.subSequence(start, end).toString();
fromUUIDString(uuidValue);
longList.add(Long.valueOf(_msb));
longList.add(Long.valueOf(_lsb));
}
}
);
return generateArrayFromList(longList);
}
public final void convertToCharacters(Object data, StringBuffer s) {
if (!(data instanceof long[])) {
throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotLongArray"));
}
final long[] ldata = (long[])data;
final int end = ldata.length - 2;
for (int i = 0; i <= end; i += 2) {
s.append(toUUIDString(ldata[i], ldata[i + 1]));
if (i != end) {
s.append(' ');
}
}
}
private long _msb;
private long _lsb;
final void fromUUIDString(String name) {
String[] components = name.split("-");
if (components.length != 5)
throw new IllegalArgumentException(CommonResourceBundle.getInstance().
getString("message.invalidUUID", new Object[]{name}));
for (int i=0; i<5; i++)
components[i] = "0x"+components[i];
_msb = Long.parseLong(components[0], 16);
_msb <<= 16;
_msb |= Long.parseLong(components[1], 16);
_msb <<= 16;
_msb |= Long.parseLong(components[2], 16);
_lsb = Long.parseLong(components[3], 16);
_lsb <<= 48;
_lsb |= Long.parseLong(components[4], 16);
}
final String toUUIDString(long msb, long lsb) {
return (digits(msb >> 32, 8) + "-" +
digits(msb >> 16, 4) + "-" +
digits(msb, 4) + "-" +
digits(lsb >> 48, 4) + "-" +
digits(lsb, 12));
}
final String digits(long val, int digits) {
long hi = 1L << (digits * 4);
return Long.toHexString(hi | (val & (hi - 1))).substring(1);
}
}