src/solaris/classes/sun/print/AttributeClass.java

Print this page




   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 
  47     public static final int TAG_TEXT_WO_LANGUAGE = 0x41;


 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 }


   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 import java.util.Objects;
  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 
  48     public static final int TAG_TEXT_WO_LANGUAGE = 0x41;


 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     public boolean equals(Object obj) {
 253         return

 254             obj instanceof AttributeClass &&
 255             toString().equals(((AttributeClass) obj).toString());
 256     }
 257  
 258     public int hashCode() {
 259         return Objects.hashCode(toString());
 260     }
 261 
 262     public String toString() {
 263         return myName;
 264     }
 265 
 266     private int unsignedByteToInt(byte b) {
 267         return (int) (b & 0xff);
 268     }
 269 
 270     private int convertToInt(byte[] buf) {
 271         int intVal = 0;
 272         int pos = 0;
 273         intVal+= unsignedByteToInt(buf[pos++]) << 24;
 274         intVal+= unsignedByteToInt(buf[pos++]) << 16;
 275         intVal+= unsignedByteToInt(buf[pos++]) << 8;
 276         intVal+= unsignedByteToInt(buf[pos++]) << 0;
 277         return intVal;
 278     }
 279 }