Java Reference
In-Depth Information
L ISTING 10.8 Continued
FileContents savedFile = fs.saveAsFileDialog(null, null, file);
} catch (Exception e) {
System.out.println(“openFile: “+e);
}
}
}
public void connectForeignHost(String url) {
try {
FileOutputStream fos = new FileOutputStream(“aFile.html”);
URL anURL = new URL(url);
URLConnection anURLConn = anURL.openConnection();
InputStream is = anURLConn.getInputStream();
int q;
while ((q = is.read()) != -1)
fos.write(q);
is.close();
fos.close();
} catch (Exception e) {
System.out.println(“connectForeignHost “+e);
}
}
public class PrintableExample implements Printable {
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex){
Graphics2D g2d = (Graphics2D)graphics;
g2d.setPaint(Color.blue);
g2d.drawString(“Print Test”,200,200);
return PAGE_EXISTS;
}
}
public static void main(String[] args) {
SecurityTester securityTester1 = new SecurityTester();
}
}
It is important to reiterate that without using the JNLP runtime services, it would be impossi-
ble to access local resources such as the printer, the system Clipboard, or local files for an
untrusted application.
10
It is interesting to try connecting to hosts different from the one the application was down-
loaded from. The method connectForeignHost (lines 64-78 of Listing 10.8) tries just that,
writing the output on a local file. For untrusted applications, the operation is immediately
blocked by the throwing of an exception.
We will discuss code like this extensively in the Chapter 11.
Search WWH ::




Custom Search