Java Printer Service throws ClassCastException while using PrinterURI Attribute
<p>I have implemented a program, to print the document to the specific printer using IP address, printer name</p>

<p>Code: </p>

<pre><code>URI myURI=null;
FileInputStream psStream=null;
try   {
       psStream = new FileInputStream( "sample.docx" );
   }
catch ( FileNotFoundException e )   {
    e.printStackTrace();
}
    DocFlavor psInFormat = DocFlavor.INPUT_STREAM.GIF;
    Doc myDoc = new SimpleDoc( psStream, psInFormat, null );
     PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add( new Copies(5) );
    try {             
        String host="192.255.301.147";
        String printer="HP LaserJet 5000 Series PCL6";
        String theUrl = "ipp://"+host+"/printers/"+printer;
        theUrl = URLEncoder.encode(theUrl, "UTF-8");
        myURI =  new URI(theUrl);       
              aset.add(new PrinterURI(myURI));  
    } catch (URISyntaxException e) {
        System.out.println("URI exception caught: "+e);         
    } catch (UnsupportedEncodingException e) {
             e.printStackTrace();
    }

  PrintService[] services = PrintServiceLookup.lookupPrintServices( psInFormat, aset );
   if ( services.length &gt; 0 ) {
     DocPrintJob job = services[0].createPrintJob();          
     try {
             job.print( myDoc, aset );
     }
     catch ( PrintException e ){
     }
}
</code></pre>

<p>While running the program, got <strong>ClasscastException</strong>.</p>

<pre><code>Exception in thread "Main Thread" java.lang.ClassCastException
    at javax.print.attribute.AttributeSetUtilities.verifyAttributeValue(AttributeSetUtilities.java:534)
    at javax.print.attribute.HashAttributeSet.add(HashAttributeSet.java:283)
    at com.src.print.TestPrint2.main(TestPrint2.java:64)
</code></pre>

<p>With out adding PrinterURI Attribute in the RequestAttributeSet (<strong><em>aset.add(new PrinterURI(myURI))</em></strong>), the Program is working fine. 
Its taking default printer configuration and printing the document.</p>

<p>Could you please help me out on this. how to use PrinterURI API?</p>
