⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 securitytestwindow.java

📁 21天学通java的示例程序源代码
💻 JAVA
字号:
/* * SecurityTestWindow.java */package com.wrox.security;import java.awt.*;import java.io.File;import java.net.URLConnection;/** * This class implements a window (java.awt.Frame) with a single text * field. The text field displays the results of the various security * tests. */class SecurityTestWindow extends Frame {  private TextArea textArea;  /**   * Constructs a security test window with the given title.   * @param title The window title.   */  public SecurityTestWindow(String title) {    super(title);    textArea = new TextArea();    textArea.setEditable(false);    add(textArea);    pack();    show();  }  /**   * Runs the security tests and displays the results.   */  public void showTestResults() {    println("Running tests...");    try {      fileTest("/");    } catch (Exception e) {      println(e);    }     try {      socketTest("http://www.wrox.com");    } catch (Exception e) {      println(e);    }     try {      systemTest("user.home");    } catch (Exception e) {      println(e);    }     println("Done.");  }   /**   * Test file (directory) access permission by taking a directory and   * displaying the first filename from it.   * @param path The directory to list   */  private void fileTest(String path) {    String[] files = new java.io.File(path).list();    if (files.length > 0) {      println("First file in " + path + " is " + files[0]);    }   }   /**   * Test network access permission by downloading a HTML page and   * displaying its length.   * @param url The URL of the page to download   */  private void socketTest(String url) throws java.io.IOException {    URLConnection connection = new java.net.URL(url).openConnection();    connection.connect();    println(url + " is " + connection.getContentLength() + " bytes");    connection.getInputStream().close();  }   /**   * Test access to privileged system properties   * @param property The name of the property to retrieve   */  private void systemTest(String property) {    println(property + " has value " + System.getProperty(property));  }   /**   * Print a line of text to the text area   * @param toPrint The object or text to print   */  private void println(Object toPrint) {    textArea.append(toPrint + "\n");  } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -