예제 #1
0
  public void executeHttpPostRequestTest() throws IOException {
    String protocol = HttpProtocol.HTTP.getValue();
    String host = "host";
    String cgiUrl = "cgiUrl";

    String requestUrl = WebUtil.prepareRequestUrl(protocol, host, cgiUrl);

    HashMap<String, Object> requestDataMap = new HashMap<String, Object>();
    requestDataMap.put("body", null);

    String responseData = WebUtil.executeHttpPostRequest(requestUrl, requestDataMap);
  }
예제 #2
0
  // 2.jpg, 3.jpg
  @Test
  public void download4() {
    try {
      String dirPath = "E:\\ACG\\犬舍\\6";
      IOUtil.createDir(dirPath);

      String baseUrl = "http://p.3qfm.com/ps1/q/quans/%E7%AC%AC06%E5%9B%9E/";
      String ext = ".jpg";
      int start = 2;
      int max = 16;
      int end = start + max;

      for (int i = start; i <= end; i++) {
        String index = Integer.toString(i);

        String filename = index + ext;
        String url = baseUrl + filename;
        String filePath = Paths.get(dirPath, filename).toString();

        WebUtil.saveFile(url, filePath);
        File img = new File(filePath);
        long imgLength = img.length();

        System.out.println("Saved " + filePath + ", " + "length:" + imgLength);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
예제 #3
0
  // Download http://url/arties/fanNo/1.jpg
  @Test
  public void downloadNumberJpg() {
    try {
      String baseUrl = "";
      String arties = "";
      String fanNo = "";
      String dir = "";
      String ext = ".jpg";
      int start = 0;
      int max = 0;

      IOUtil.createDir(dir);

      for (int i = start; i <= max; i++) {
        String filename = i + ext;
        String requestUrl = baseUrl + "/" + arties + "/" + fanNo + "/" + filename;
        String filePath = dir + "\\" + filename;

        WebUtil.saveFile(requestUrl, filePath);
        File img = new File(filePath);
        long imgLength = img.length();

        System.out.println("Saved " + filePath + ", " + "length:" + imgLength);

        if (isEnded(imgLength)) {
          break;
        }
      }
    } catch (Exception ex) {
      System.out.println(ex);
    }
  }
예제 #4
0
 public void testSingleFile() {
   try {
     String url = "";
     String filePath = "";
     WebUtil.saveFile(url, filePath);
     System.out.println("Saved " + filePath);
   } catch (Exception ex) {
     System.out.println(ex);
   }
 }
예제 #5
0
  // 000001.jpg, 001002.jpg
  @Test
  public void download1() {
    try {
      String dirPath = "E:\\ACG\\犬舍\\4";
      IOUtil.createDir(dirPath);

      String baseUrl = "http://p.3qfm.com/ps1/q/quans/act_04/";
      String ext = ".jpg";
      int max = 21;

      for (int i = 1; i <= max; i++) {
        String index = Integer.toString(i);
        String part1 = "";
        String part2 = "";
        String zero = "";

        if (index.length() == 1) {
          zero = "00";
        } else if (index.length() == 2) {
          zero = "0";
        }

        part1 = zero + (i - 1);
        part2 = zero + i;

        String filename = part1 + part2 + ext;
        String url = baseUrl + filename;
        String filePath = Paths.get(dirPath, filename).toString();

        WebUtil.saveFile(url, filePath);
        File img = new File(filePath);
        long imgLength = img.length();

        System.out.println("Saved " + filePath + ", " + "length:" + imgLength);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }