input
stringlengths
10
828
output
stringlengths
5
107
private void change player playing player player one playing player player two player player one
switch between the players
private void finish hand if is game over int play count 1 list integer totals new array list integer 10 for int i 0 i 3 i list player player board get i int pos 0 for player line player if line playing totals add box value i pos pos play count if totals size 3 int sum 0 for integer value totals sum value if array utils contains possible sum won player playing break if play count 9 won player null won player player tie change player
check if the game is over
public void test play up horizontal tic tac toe game game new tic tac toe game player one game play player one board box up left game play player two board box middle left game play player one board box up middle game play player two board box middle middle game play player one board box up right game play player two board box middle right assert equals game get won player player one
x x x
protected document handler create document handler data source source return new document handler source
create an instance of document handler
protected validation result create error result parse exception e if e instanceof pdf parse exception if e get cause null return new validation result new validation error pdf parse exception e get error code else if e get cause get message null return new validation result new validation error pdf parse exception e get error code else return new validation result new validation error pdf parse exception e get error code e get cause get message return create unknown error result
create an instance of validation result
protected validation result create unknown error result validation error error new validation error validation constants error unkown error validation result result new validation result error return result
create an instance of validation result with a
public void close pdf cosutils close document quietly this pdf
close the instance of pddocument contained by this
public void add error validation error error if error null this l errors add error
add error to the list of validation error
private boolean is count entry present cosdictionary outline return outline get item cosname get pdfname count null
return true if the count entry is present in the given dictionary
protected void init font validator factory this font validation factory new font validator factory
instantiate the font validator factory used by the font validation helper
protected cosdictionary is linearized pdf pddocument document get ref to obj cosdocument c doc document get document list l obj c doc get objects for object object l obj cosbase cur obj cosobject object get object if cur obj instanceof cosdictionary cosdictionary cur obj key set contains cosname get pdfname dictionary key linearized return cosdictionary cur obj return null
according to the pdf reference a linearized pdf contain a dictionary as
protected void set parser pdfparser parser this parser parser
initialize the java cc parser which checks the syntax of the pdf
protected void set pdf extractor extractor token manager pdf extractor this pdf extractor pdf extractor
initialize the pdf extractor attribute
protected void set document pddocument document this document document
initialize the pdfbox object which present the pdf file
public void add font cosbase f key abstract font container fc this embedded fonts put f key fc
add a font container to allow text object validation
public abstract font container get font cosbase f key return this embedded fonts get f key
return the font container identified by the cosbase
public void close cosutils close document quietly document
close all opened resources
protected boolean check dest list validation error errors try pddestination dest this pd link get destination if dest null check the if an a entry is present if this pd link get action null errors add new validation result validation error validation constants error annot forbidden dest dest can t be used due to a element return false catch ioexception e errors add new validation result validation error validation constants error annot invalid dest dest can t be checked return false return true
check if the dest element is authorized according to the a entry
protected boolean check flags list validation error errors boolean result this pd annot is printed result result this pd annot is hidden result result this pd annot is invisible result result this pd annot is no view if result errors add new validation result validation error validation constants error annot forbidden flag flags of pd annot get subtype annotation are invalid return result
checks if flags of the annotation are authorized
protected boolean check ca list validation error errors cosbase ca this pd annot get dictionary get item cosname get pdfname annot dictionary key ca if ca null float caf this pd annot get dictionary get float cosname get pdfname annot dictionary key ca if caf 1 0f only 1 0 is authorized as value errors add new validation result validation error validation constants error annot invalid ca ca entry is invalid expected 1 0 read caf return false else optional field ok return true
check if the ca value is 1
protected boolean search rgbprofile iccprofile wrapper iccpw this handler get icc profile wrapper if iccpw null return iccpw is rgbcolor space return false
search the rgb profile in output intents dictionaries
public boolean validate transparency rules list validation error error boolean res true for cosdictionary egs list of ext gstate res res check soft mask egs error res res check ca egs error res res check blend mode egs error res res check trkey egs error res res check tr2 key egs error return res
validate all ext gstate dictionaries of this container
protected boolean check smask list validation error error cosbase smask xobject get item cosname get pdfname transparency dictionary key soft mask if smask null cosutils is string smask cos document transparency dictionary value soft mask none equals cosutils get as string smask cos document error add new validation error error graphic transparency smask soft mask must be null or none return false return true
this method checks the smask entry in the xobject dictionary
protected boolean check opi list validation error errors 6 2 4 and 6 2 5 no opi if this xobject get item cosname get pdfname opi null errors add new validation error validation constants error graphic unexpected key unexpected opi key return false return true
according the iso 190005 1 2005 specification a xobject cant have an opi
protected boolean check reference xobject list validation error errors 6 2 6 no reference xobject if this xobject get item cosname get pdfname ref null errors add new validation error error graphic unexpected key no reference xobject allowed in pdf a return false return true
according the iso 190005 1 2005 specification a xobject cant have an ref
private boolean check soft mask cosdictionary egs list validation error error cosbase sm val egs get item cosname get pdfname transparency dictionary key soft mask if sm val null soft mask is valid only if it is a cosname equals to none if sm val instanceof cosname transparency dictionary value soft mask none equals cosname sm val get name error add new validation error error transparency ext gs soft mask soft mask must be null or none return false return true
this method checks the smask value of the ext gstate dictionary
protected boolean check postscript xobject list validation error errors 6 2 7 no post script xobjects if this xobject get item cosname subtype null xobject dictionary value subtype postscript equals this xobject get name as string cosname subtype errors add new validation error error graphic unexpected value for key no postscript xobject allowed in pdf a return false if this xobject get item cosname get pdfname subtype2 null errors add new validation error error graphic unexpected value for key no postscript xobject allowed in pdf a subtype2 return false return true
according the iso 190005 1 2005 specification post script xobject are
private boolean check blend mode cosdictionary egs list validation error error cosbase bm val egs get item cosname get pdfname transparency dictionary key blend mode if bm val null blend mode is valid only if it is equals to normal or compatible if bm val instanceof cosname transparency dictionary value bm normal equals cosname bm val get name transparency dictionary value bm compatible equals cosname bm val get name error add new validation error error transparency ext gs blend mode blend mode value isn t valid only normal and compatible are authorized return false return true
this method checks the bm value of the ext gstate dictionary
protected boolean check trkey cosdictionary egs list validation error error if egs get item cosname get pdfname tr null error add new validation error validation constants error graphic unexpected key no tr key expected in extended graphics state return false return true
check the tr entry
protected boolean check tr2 key cosdictionary egs list validation error error if egs get item cosname get pdfname tr2 null string s egs get name as string cosname get pdfname tr2 if default equals s error add new validation error validation constants error graphic unexpected value for key tr2 key only expect default value not s return false return true
check the tr2 entry
protected boolean process pattern color space list validation error result result add new validation error error graphic invalid pattern color space forbidden pattern color space is forbidden return false
this method updates the given list with a validation error
protected boolean process pattern color space list validation error result result add new validation error error graphic invalid color space forbidden pattern color space is forbidden return false
this method updates the given list with a validation error
protected boolean check rikey cosdictionary egs list validation error error string rendenring intent egs get name as string cosname get pdfname ri if rendenring intent null equals rendenring intent rendering intents contains rendenring intent error add new validation error validation constants error graphic unexpected value for key invalid rendering intent value in extended graphics state return false return true
check the ri entry of the graphic state
protected boolean process calibrated color space list validation error result result add new validation error error graphic invalid color space forbidden calibrated color space is forbidden return false
this method updates the given list with a validation error
protected boolean check mandatory fields list validation error errors boolean res pattern get item cosname get pdfname dictionary key resources null res res pattern get item cosname get pdfname pattern key bbox null res res pattern get item cosname get pdfname pattern key paint type null res res pattern get item cosname get pdfname pattern key tiling type null res res pattern get item cosname get pdfname pattern key xstep null res res pattern get item cosname get pdfname pattern key ystep null if res errors add new validation error error graphic invalid pattern definition return res
this method checks if required fields are present
public int get color space type return color space get type
call the icc color space
public boolean is rgbcolor space return icc color space type rgb color space get type
return true if the colour space is rgb
public boolean is cmykcolor space return icc color space type cmyk color space get type
return true if the colour space is cmyk
public boolean is gray color space return icc color space type gray color space get type
return true if the colour space is gray scale
protected boolean check ps list validation error errors 6 2 4 and 6 2 5 no ps if this xobject get item cosname get pdfname ps null errors add new validation error validation constants error graphic unexpected key unexpected ps key return false return true
check if there are no ps entry in the form xobject dictionary
protected boolean check subtype2 value list validation error errors 6 2 5 if subtype2 value not ps if this xobject get item cosname get pdfname subtype2 null if ps equals this xobject get name as string cosname get pdfname subtype2 errors add new validation error validation constants error graphic unexpected value for key unexpected ps value for subtype2 key return false return true
check the subtype2 entry according to the 6
private void extract elements to check here is required elements this basefont f dictionary get name as string cosname get pdfname font dictionary key basefont this first char f dictionary get item cosname get pdfname font dictionary key firstchar this last char f dictionary get item cosname get pdfname font dictionary key lastchar this widths f dictionary get item cosname get pdfname font dictionary key widths here is optional elements this encoding f dictionary get item cosname get pdfname font dictionary key encoding this to unicode f dictionary get item cosname get pdfname font dictionary key tounicode
extract element from the cosobject to avoid useless access to this object
protected boolean check font name string font name this p font desc get font name if font name null this font container add error new validation result validation error validation constants error fonts descriptor invalid the font name in font descriptor is null return false return true
if the font name is missing from the font descriptor dictionary this method
public void close ioutils close quietly this font
close the font stream
private boolean check mandatory fields boolean all this font bbox null all all this font matrix null all all this char procs null all all this font encoding null all all this first char null all all this last char null all all this widths null if all this font container add error new validation error error fonts dictionary invalid since pdf 1 5 font descriptor is mandatory for type3 font however because of the font descriptor is optional in pdf 1 4 no specific checks are processed for pdf a validation return all
returns true if all required fields are present
protected void compute eexec throws validation exception try byte eexec read eexec byte decrypted eexec decode eexec eexec uncomment this to see eexec as clear text system out println decoded eexec system out println new string decrypted eexec parse decoded eexec decrypted eexec catch ioexception e throw new validation exception unable to compute the eexec portion e get message e
this method read eexec size bytes
protected string get label as name int cid string label null try label this encoding get name cid catch ioexception e label this cid to label get cid if label null label notdef return label char at 0 name start label name start label
returns the character name as pdf name object
public int get width int cid string label get label as name cid type1 glyph description glyph this label to metric get label if glyph null return glyph get width return 0
return the glyph width according to the character identifier
public image create image cosstream type3 stream throws ioexception reset engine process sub stream null null type3 stream return image create image
this will parse a type3 stream and create an image from it
public pdfont get font return font
return the pdfont object
public void add error validation error error this errors add error
addition of a validation error
public state is valid if this errors is empty return state valid if this errors size 1 this is font program embedded return state maybe else more than one error the validation failed return state invalid
this method returns the validation state of the font
private content stream exception create invalid arguments error content stream exception ex new content stream exception ex set validation error error syntax content stream invalid argument return ex
create a content stream exception with
private content stream exception create limit error string error code string details content stream exception ex new content stream exception details ex set validation error error code return ex
create a content stream exception with
public boolean valid list validation error error throws validation exception return valid false error
call the valid boolean list method with the additonal action auth set to
public cosdictionary parse as dictionary throws ioexception return parse cosdictionary
parse the input byte array of the constructor call as a cosdictionary
public cosdocument get document return this document
return the cosdocument used to create this object
protected validation error unsynchronized meta data error string target string builder sb new string builder 80 sb append target append present in the document catalog dictionary doesn t match with xmp information return new validation error validation constants error metadata mismatch sb to string
return a formatted validation error when metadata are not synchronized
public void test invalid font throws exception int length1 926 int length2 12270 input stream font this get class get resource as stream true type ttf type1 metric helper helper new type1 metric helper font length1 length2 font dictionary value encoding win helper parse fail
a invalid type1 font program is parsed by the metric helper
protected validation error absent xmpproperty error string target string details string builder sb new string builder 80 sb append target append present in the document catalog dictionary can t be found in xmp information append details append return new validation error validation constants error metadata mismatch sb to string
return a formatted validation error when a specific xmp property cant be
public xmpschema pdfafield get pdfafield schema throws ioexception return xmpschema pdfafield get schema by class xmpschema pdfafield class
get the pdfafield schema
public xmpschema pdfaid get pdfaid schema throws ioexception return xmpschema pdfaid get schema by class xmpschema pdfaid class
get the pdfa id schema
public xmpschema pdfaproperty get pdfaproperty schema throws ioexception return xmpschema pdfaproperty get schema by class xmpschema pdfaproperty class
get the pdfa property schema
public xmpschema pdfaschema get pdfaschema throws ioexception return xmpschema pdfaschema get schema by class xmpschema pdfaschema class
get the pdfa schema
public xmpschema pdfatype get pdfatype schema throws ioexception return xmpschema pdfatype get schema by class xmpschema pdfatype class
get the pdfa type schema
public encoding get standard encoding return standard encoding instance
this will get the standard encoding
public encoding get encoding cosname name throws ioexception if cosname standard encoding equals name return standard encoding instance else if cosname win ansi encoding equals name return win ansi encoding instance else if cosname mac roman encoding equals name return mac roman encoding instance else if cosname pdf doc encoding equals name return pdf doc encoding instance else throw new ioexception unknown encoding for name get name
this will get an encoding by name
public void draw image image awt image affine transform at graphics set composite get graphics state get stroke java composite graphics set clip get graphics state get current clipping path graphics draw image awt image at null
draw the awt image
public cosdocument get document throws ioexception if document null throw new ioexception you must call parse before calling get document return document
this will get the document that was parsed
public pddocument get pddocument throws ioexception return doc
this will get the pd document that was parsed
protected byte consume whitespace backwards throws ioexception input file seek current offset byte single byte byte input file read if is whitespace single byte return single byte we have some whitespace let s consume it while is whitespace single byte single byte read byte backwards read byte backwards will decrement the current offset to point the byte before the one just read so we increment it back to the current byte current offset return single byte
this will read all bytes backwards until a non whitespace character is
protected byte consume whitespace throws ioexception input file seek current offset byte single byte byte input file read if is whitespace single byte return single byte we have some whitespace let s consume it while is whitespace single byte single byte read byte read byte will increment the current offset to point the byte after the one just read so we decrement it back to the current byte current offset return single byte
this will read all bytes until a non whitespace character is
protected long read long backwards throws ioexception number format exception string builder sb new string builder consume whitespace backwards byte single byte read byte backwards while is whitespace single byte sb insert 0 char single byte single byte read byte backwards if sb length 0 throw new assertion error number not found expected number at offset current offset return long parse long sb to string
this will consume any whitespace read in bytes until whitespace is found
protected string read line backwards throws ioexception string builder sb new string builder boolean end of object false do first we read the eof marker byte single byte read byte backwards if single byte n if ther s a preceeding r we ll eat that as well input file seek current offset if byte input file read r current offset end of object true else if single byte r end of object true else sb insert 0 char single byte while end of object return sb to string
this will read a line starting with the byte at offset and going
public printer job get printer job return job
returns the printer job for printing the given pdf document
public int get number of pages return pages size
returns the number of pages in the given pdf document
public string get article start return article start
returns the string which will be used at the beginning of an article
public void set article start string article start this article start article start
sets the string which will be used at the beginning of an article
public string get article end return article end
returns the string which will be used at the end of an article
public void set article end string article end this article end article end
sets the string which will be used at the end of an article
protected void write paragraph separator throws ioexception write paragraph end write paragraph start
writes the paragraph separator string to the output
protected void write paragraph start throws ioexception output write get paragraph start
write something if defined at the start of a paragraph
protected void write paragraph end throws ioexception output write get paragraph end
write something if defined at the end of a paragraph
protected void write page start throws ioexception output write get page start
write something if defined at the start of a page
protected void write page end throws ioexception output write get page end
write something if defined at the end of a page
protected pattern match list item pattern position wrapper pw text position tp pw get text position string txt tp get character pattern p match pattern txt get list item patterns return p
returns the list item pattern object that matches
protected void set list item patterns list pattern patterns li patterns patterns
use to supply a different set of regular expression
private void write line list string line boolean is rtl dominant throws ioexception int number of strings line size if is rtl dominant for int i number of strings 1 i 0 i if i number of strings 1 write word separator write string line get i else for int i 0 i number of strings i write string line get i if is rtl dominant i number of strings 1 write word separator
write a list of string containing a whole line of a document
public color space get java color space throws ioexception if color space null color space create color space return color space
returns the java awt color space for this instance
public color get java color throws ioexception if color null color space value size 0 color create color return color
returns the java awt color based on the current color space and value
public cosbase get object from pool cosobject key key throws ioexception return object pool get key
this will get an object from the pool
public cosbase get object from pool long number long generation throws ioexception return object pool get new cosobject key number generation
this will get an object from the pool
public void test date conversion throws exception calendar c date converter to calendar d 20050526205258 01 00 assert equals 2005 c get calendar year assert equals 05 1 c get calendar month assert equals 26 c get calendar day of month assert equals 20 c get calendar hour of day assert equals 52 c get calendar minute assert equals 58 c get calendar second assert equals 0 c get calendar millisecond
test case for
public void test labels on malformed pdf throws exception pddocument doc null try doc pddocument load test pddocument catalog class get resource as stream page label pdf pddocument catalog cat doc get document catalog get labels by page indices should not throw an exception cat get page labels get labels by page indices catch exception e fail threw exception finally if doc null doc close
test case for
public void test get number of pages throws exception pddocument doc null try doc pddocument load test pddocument catalog class get resource test unc pdf assert equals 4 doc get number of pages finally if doc null doc close
test case for
public void test page map throws exception pddocument doc null try doc pddocument load test pddocument catalog class get resource test unc pdf assert equals 4 doc get page map size int page num doc get page map get 14 0 assert equals 1 page num finally if doc null doc close
test case for
public void add to owner value string value add bag value local prefix sep owner value
add a legal owner for the described resource
public complex property get owner return complex property get property local prefix sep owner
return the bag of owner s
public void set marked boolean type marked add property marked
set marked property
public boolean type get marked return boolean type get property local prefix sep marked
get marked property