Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | * |
aoqi@0 | 25 | * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
aoqi@0 | 26 | */ |
aoqi@0 | 27 | |
aoqi@0 | 28 | package com.sun.xml.internal.fastinfoset.algorithm; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import java.io.EOFException; |
aoqi@0 | 31 | import java.io.IOException; |
aoqi@0 | 32 | import java.io.InputStream; |
aoqi@0 | 33 | import java.io.OutputStream; |
aoqi@0 | 34 | import java.nio.CharBuffer; |
aoqi@0 | 35 | import java.util.ArrayList; |
aoqi@0 | 36 | import java.util.List; |
aoqi@0 | 37 | import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException; |
aoqi@0 | 38 | import com.sun.xml.internal.fastinfoset.CommonResourceBundle; |
aoqi@0 | 39 | |
aoqi@0 | 40 | |
aoqi@0 | 41 | |
aoqi@0 | 42 | public class DoubleEncodingAlgorithm extends IEEE754FloatingPointEncodingAlgorithm { |
aoqi@0 | 43 | |
aoqi@0 | 44 | public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException { |
aoqi@0 | 45 | if (octetLength % DOUBLE_SIZE != 0) { |
aoqi@0 | 46 | throw new EncodingAlgorithmException(CommonResourceBundle.getInstance(). |
aoqi@0 | 47 | getString("message.lengthIsNotMultipleOfDouble", new Object[]{Integer.valueOf(DOUBLE_SIZE)})); |
aoqi@0 | 48 | } |
aoqi@0 | 49 | |
aoqi@0 | 50 | return octetLength / DOUBLE_SIZE; |
aoqi@0 | 51 | } |
aoqi@0 | 52 | |
aoqi@0 | 53 | public int getOctetLengthFromPrimitiveLength(int primitiveLength) { |
aoqi@0 | 54 | return primitiveLength * DOUBLE_SIZE; |
aoqi@0 | 55 | } |
aoqi@0 | 56 | |
aoqi@0 | 57 | public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException { |
aoqi@0 | 58 | double[] data = new double[getPrimtiveLengthFromOctetLength(length)]; |
aoqi@0 | 59 | decodeFromBytesToDoubleArray(data, 0, b, start, length); |
aoqi@0 | 60 | |
aoqi@0 | 61 | return data; |
aoqi@0 | 62 | } |
aoqi@0 | 63 | |
aoqi@0 | 64 | public final Object decodeFromInputStream(InputStream s) throws IOException { |
aoqi@0 | 65 | return decodeFromInputStreamToDoubleArray(s); |
aoqi@0 | 66 | } |
aoqi@0 | 67 | |
aoqi@0 | 68 | |
aoqi@0 | 69 | public void encodeToOutputStream(Object data, OutputStream s) throws IOException { |
aoqi@0 | 70 | if (!(data instanceof double[])) { |
aoqi@0 | 71 | throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotDouble")); |
aoqi@0 | 72 | } |
aoqi@0 | 73 | |
aoqi@0 | 74 | final double[] fdata = (double[])data; |
aoqi@0 | 75 | |
aoqi@0 | 76 | encodeToOutputStreamFromDoubleArray(fdata, s); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | public final Object convertFromCharacters(char[] ch, int start, int length) { |
aoqi@0 | 80 | final CharBuffer cb = CharBuffer.wrap(ch, start, length); |
aoqi@0 | 81 | final List doubleList = new ArrayList(); |
aoqi@0 | 82 | |
aoqi@0 | 83 | matchWhiteSpaceDelimnatedWords(cb, |
aoqi@0 | 84 | new WordListener() { |
aoqi@0 | 85 | public void word(int start, int end) { |
aoqi@0 | 86 | String fStringValue = cb.subSequence(start, end).toString(); |
aoqi@0 | 87 | doubleList.add(Double.valueOf(fStringValue)); |
aoqi@0 | 88 | } |
aoqi@0 | 89 | } |
aoqi@0 | 90 | ); |
aoqi@0 | 91 | |
aoqi@0 | 92 | return generateArrayFromList(doubleList); |
aoqi@0 | 93 | } |
aoqi@0 | 94 | |
aoqi@0 | 95 | public final void convertToCharacters(Object data, StringBuffer s) { |
aoqi@0 | 96 | if (!(data instanceof double[])) { |
aoqi@0 | 97 | throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotDouble")); |
aoqi@0 | 98 | } |
aoqi@0 | 99 | |
aoqi@0 | 100 | final double[] fdata = (double[])data; |
aoqi@0 | 101 | |
aoqi@0 | 102 | convertToCharactersFromDoubleArray(fdata, s); |
aoqi@0 | 103 | } |
aoqi@0 | 104 | |
aoqi@0 | 105 | |
aoqi@0 | 106 | public final void decodeFromBytesToDoubleArray(double[] data, int fstart, byte[] b, int start, int length) { |
aoqi@0 | 107 | final int size = length / DOUBLE_SIZE; |
aoqi@0 | 108 | for (int i = 0; i < size; i++) { |
aoqi@0 | 109 | final long bits = |
aoqi@0 | 110 | ((long)(b[start++] & 0xFF) << 56) | |
aoqi@0 | 111 | ((long)(b[start++] & 0xFF) << 48) | |
aoqi@0 | 112 | ((long)(b[start++] & 0xFF) << 40) | |
aoqi@0 | 113 | ((long)(b[start++] & 0xFF) << 32) | |
aoqi@0 | 114 | ((long)(b[start++] & 0xFF) << 24) | |
aoqi@0 | 115 | ((long)(b[start++] & 0xFF) << 16) | |
aoqi@0 | 116 | ((long)(b[start++] & 0xFF) << 8) | |
aoqi@0 | 117 | (long)(b[start++] & 0xFF); |
aoqi@0 | 118 | data[fstart++] = Double.longBitsToDouble(bits); |
aoqi@0 | 119 | } |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | public final double[] decodeFromInputStreamToDoubleArray(InputStream s) throws IOException { |
aoqi@0 | 123 | final List doubleList = new ArrayList(); |
aoqi@0 | 124 | final byte[] b = new byte[DOUBLE_SIZE]; |
aoqi@0 | 125 | |
aoqi@0 | 126 | while (true) { |
aoqi@0 | 127 | int n = s.read(b); |
aoqi@0 | 128 | if (n != DOUBLE_SIZE) { |
aoqi@0 | 129 | if (n == -1) { |
aoqi@0 | 130 | break; |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | while(n != DOUBLE_SIZE) { |
aoqi@0 | 134 | final int m = s.read(b, n, DOUBLE_SIZE - n); |
aoqi@0 | 135 | if (m == -1) { |
aoqi@0 | 136 | throw new EOFException(); |
aoqi@0 | 137 | } |
aoqi@0 | 138 | n += m; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | } |
aoqi@0 | 141 | |
aoqi@0 | 142 | final long bits = |
aoqi@0 | 143 | ((long)(b[0] & 0xFF) << 56) | |
aoqi@0 | 144 | ((long)(b[1] & 0xFF) << 48) | |
aoqi@0 | 145 | ((long)(b[2] & 0xFF) << 40) | |
aoqi@0 | 146 | ((long)(b[3] & 0xFF) << 32) | |
aoqi@0 | 147 | ((b[4] & 0xFF) << 24) | |
aoqi@0 | 148 | ((b[5] & 0xFF) << 16) | |
aoqi@0 | 149 | ((b[6] & 0xFF) << 8) | |
aoqi@0 | 150 | (b[7] & 0xFF); |
aoqi@0 | 151 | |
aoqi@0 | 152 | doubleList.add(Double.valueOf(Double.longBitsToDouble(bits))); |
aoqi@0 | 153 | } |
aoqi@0 | 154 | |
aoqi@0 | 155 | return generateArrayFromList(doubleList); |
aoqi@0 | 156 | } |
aoqi@0 | 157 | |
aoqi@0 | 158 | |
aoqi@0 | 159 | public final void encodeToOutputStreamFromDoubleArray(double[] fdata, OutputStream s) throws IOException { |
aoqi@0 | 160 | for (int i = 0; i < fdata.length; i++) { |
aoqi@0 | 161 | final long bits = Double.doubleToLongBits(fdata[i]); |
aoqi@0 | 162 | s.write((int)((bits >>> 56) & 0xFF)); |
aoqi@0 | 163 | s.write((int)((bits >>> 48) & 0xFF)); |
aoqi@0 | 164 | s.write((int)((bits >>> 40) & 0xFF)); |
aoqi@0 | 165 | s.write((int)((bits >>> 32) & 0xFF)); |
aoqi@0 | 166 | s.write((int)((bits >>> 24) & 0xFF)); |
aoqi@0 | 167 | s.write((int)((bits >>> 16) & 0xFF)); |
aoqi@0 | 168 | s.write((int)((bits >>> 8) & 0xFF)); |
aoqi@0 | 169 | s.write((int)(bits & 0xFF)); |
aoqi@0 | 170 | } |
aoqi@0 | 171 | } |
aoqi@0 | 172 | |
aoqi@0 | 173 | public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) { |
aoqi@0 | 174 | encodeToBytesFromDoubleArray((double[])array, astart, alength, b, start); |
aoqi@0 | 175 | } |
aoqi@0 | 176 | |
aoqi@0 | 177 | public final void encodeToBytesFromDoubleArray(double[] fdata, int fstart, int flength, byte[] b, int start) { |
aoqi@0 | 178 | final int fend = fstart + flength; |
aoqi@0 | 179 | for (int i = fstart; i < fend; i++) { |
aoqi@0 | 180 | final long bits = Double.doubleToLongBits(fdata[i]); |
aoqi@0 | 181 | b[start++] = (byte)((bits >>> 56) & 0xFF); |
aoqi@0 | 182 | b[start++] = (byte)((bits >>> 48) & 0xFF); |
aoqi@0 | 183 | b[start++] = (byte)((bits >>> 40) & 0xFF); |
aoqi@0 | 184 | b[start++] = (byte)((bits >>> 32) & 0xFF); |
aoqi@0 | 185 | b[start++] = (byte)((bits >>> 24) & 0xFF); |
aoqi@0 | 186 | b[start++] = (byte)((bits >>> 16) & 0xFF); |
aoqi@0 | 187 | b[start++] = (byte)((bits >>> 8) & 0xFF); |
aoqi@0 | 188 | b[start++] = (byte)(bits & 0xFF); |
aoqi@0 | 189 | } |
aoqi@0 | 190 | } |
aoqi@0 | 191 | |
aoqi@0 | 192 | |
aoqi@0 | 193 | public final void convertToCharactersFromDoubleArray(double[] fdata, StringBuffer s) { |
aoqi@0 | 194 | final int end = fdata.length - 1; |
aoqi@0 | 195 | for (int i = 0; i <= end; i++) { |
aoqi@0 | 196 | s.append(Double.toString(fdata[i])); |
aoqi@0 | 197 | if (i != end) { |
aoqi@0 | 198 | s.append(' '); |
aoqi@0 | 199 | } |
aoqi@0 | 200 | } |
aoqi@0 | 201 | } |
aoqi@0 | 202 | |
aoqi@0 | 203 | |
aoqi@0 | 204 | public final double[] generateArrayFromList(List array) { |
aoqi@0 | 205 | double[] fdata = new double[array.size()]; |
aoqi@0 | 206 | for (int i = 0; i < fdata.length; i++) { |
aoqi@0 | 207 | fdata[i] = ((Double)array.get(i)).doubleValue(); |
aoqi@0 | 208 | } |
aoqi@0 | 209 | |
aoqi@0 | 210 | return fdata; |
aoqi@0 | 211 | } |
aoqi@0 | 212 | |
aoqi@0 | 213 | } |