7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package sun.print;
26
27 import java.io.ByteArrayInputStream;
28
29 public class AttributeClass {
30 private String myName;
31 private int myType;
32 private int nameLen;
33 private Object myValue;
34
35 public static final int TAG_UNSUPPORTED_VALUE = 0x10;
36 public static final int TAG_INT = 0x21;
37 public static final int TAG_BOOL = 0x22;
38 public static final int TAG_ENUM = 0x23;
39 public static final int TAG_OCTET = 0x30;
40 public static final int TAG_DATE = 0x31;
41 public static final int TAG_RESOLUTION = 0x32;
42 public static final int TAG_RANGE_INTEGER = 0x33;
43
44 public static final int TAG_TEXT_LANGUAGE = 0x35;
45 public static final int TAG_NAME_LANGUAGE = 0x36;
46
231
232 /**
233 * Returns single byte value.
234 */
235 public byte getByteValue() {
236 byte[] bufArray = (byte[])myValue;
237
238 if ((bufArray != null) && (bufArray.length>=2)) {
239 return bufArray[1];
240 }
241 return 0;
242 }
243
244 /**
245 * Returns attribute name.
246 */
247 public String getName() {
248 return myName;
249 }
250
251 public boolean equals(Object obj) {
252 return
253 obj != null &&
254 obj instanceof AttributeClass &&
255 obj.toString().equals (((AttributeClass) obj).toString());
256 }
257
258 public String toString() {
259 return myName;
260 }
261
262 private int unsignedByteToInt(byte b) {
263 return (int) (b & 0xff);
264 }
265
266 private int convertToInt(byte[] buf) {
267 int intVal = 0;
268 int pos = 0;
269 intVal+= unsignedByteToInt(buf[pos++]) << 24;
270 intVal+= unsignedByteToInt(buf[pos++]) << 16;
271 intVal+= unsignedByteToInt(buf[pos++]) << 8;
272 intVal+= unsignedByteToInt(buf[pos++]) << 0;
273 return intVal;
274 }
275 }
|
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package sun.print;
26
27 import java.util.Objects;
28 import java.io.ByteArrayInputStream;
29
30 public class AttributeClass {
31 private String myName;
32 private int myType;
33 private int nameLen;
34 private Object myValue;
35
36 public static final int TAG_UNSUPPORTED_VALUE = 0x10;
37 public static final int TAG_INT = 0x21;
38 public static final int TAG_BOOL = 0x22;
39 public static final int TAG_ENUM = 0x23;
40 public static final int TAG_OCTET = 0x30;
41 public static final int TAG_DATE = 0x31;
42 public static final int TAG_RESOLUTION = 0x32;
43 public static final int TAG_RANGE_INTEGER = 0x33;
44
45 public static final int TAG_TEXT_LANGUAGE = 0x35;
46 public static final int TAG_NAME_LANGUAGE = 0x36;
47
232
233 /**
234 * Returns single byte value.
235 */
236 public byte getByteValue() {
237 byte[] bufArray = (byte[])myValue;
238
239 if ((bufArray != null) && (bufArray.length>=2)) {
240 return bufArray[1];
241 }
242 return 0;
243 }
244
245 /**
246 * Returns attribute name.
247 */
248 public String getName() {
249 return myName;
250 }
251
252 @Override
253 public boolean equals(Object obj) {
254 if (!(obj instanceof AttributeClass)) {
255 return false;
256 }
257 if (this == obj) {
258 return true;
259 }
260
261 AttributeClass acObj = (AttributeClass) obj;
262 return myType == acObj.getType() &&
263 Objects.equals(myName, acObj.getName()) &&
264 Objects.equals(myValue, acObj.getObjectValue());
265 }
266
267 @Override
268 public int hashCode() {
269 return Objects.hash(myType, myName, myValue);
270 }
271
272 public String toString() {
273 return myName;
274 }
275
276 private int unsignedByteToInt(byte b) {
277 return (int) (b & 0xff);
278 }
279
280 private int convertToInt(byte[] buf) {
281 int intVal = 0;
282 int pos = 0;
283 intVal+= unsignedByteToInt(buf[pos++]) << 24;
284 intVal+= unsignedByteToInt(buf[pos++]) << 16;
285 intVal+= unsignedByteToInt(buf[pos++]) << 8;
286 intVal+= unsignedByteToInt(buf[pos++]) << 0;
287 return intVal;
288 }
289 }
|