1 31 package org.pdfbox.cos; 32 33 import java.io.IOException ; 34 import java.io.OutputStream ; 35 36 import org.pdfbox.exceptions.COSVisitorException; 37 38 45 public class COSInteger extends COSNumber 46 { 47 48 private long value; 49 50 55 public COSInteger( long val ) 56 { 57 value = val; 58 } 59 60 65 public COSInteger( int val ) 66 { 67 this( (long)val ); 68 } 69 70 77 public COSInteger( String val ) throws IOException 78 { 79 try 80 { 81 value = Long.parseLong( val ); 82 } 83 catch( NumberFormatException e ) 84 { 85 throw new IOException ( "Error: value is not an integer type actual='" + val + "'" ); 86 } 87 } 88 89 92 public boolean equals(Object o) 93 { 94 return o instanceof COSInteger && ((COSInteger)o).intValue() == intValue(); 95 } 96 97 100 public int hashCode() 101 { 102 return (int)(value ^ (value >> 32)); 104 } 105 106 109 public String toString() 110 { 111 return "COSInt{" + value + "}"; 112 } 113 114 119 public void setValue( long newValue ) 120 { 121 value = newValue; 122 } 123 124 129 public float floatValue() 130 { 131 return value; 132 } 133 134 139 public double doubleValue() 140 { 141 return value; 142 } 143 144 150 public int intValue() 151 { 152 return (int)value; 153 } 154 155 161 public long longValue() 162 { 163 return value; 164 } 165 166 173 public Object accept(ICOSVisitor visitor) throws COSVisitorException 174 { 175 return visitor.visitFromInt(this); 176 } 177 178 184 public void writePDF( OutputStream output ) throws IOException 185 { 186 output.write(String.valueOf(value).getBytes()); 187 } 188 } | Popular Tags |