Exemplo n.º 1
0
 @Override
 public void run() {
   try {
     if (!picDirectory.exists()) picDirectory.mkdirs();
     File csvPath = csvFile.getParentFile();
     if ((csvPath != null) && !csvPath.exists()) csvPath.mkdirs();
     PrintWriter csvWrite = new PrintWriter(csvFile);
     for (int i = 0; i < id.length; i++) {
       progressBar.setValue(i * 100 / id.length);
       csvWrite.print("'" + id[i] + "'");
       Detail info = new Detail(frame.database, id[i]);
       for (int x = 0; x < 7; x++)
         for (int y = 0; y < 7; y++) {
           String data = info.get(List.COLUMN_NAME[x][y]);
           switch (List.COLUMN_TYPE[x][y]) {
             case 1:
               data = "'" + data + "'";
               break;
             case 2:
               if (data == null) data = "null";
               break;
             case 3:
               if (data == null) data = "0000-00-00";
               data = "'" + data + "'";
               break;
             case 4:
               data = "'" + data + "'";
           }
           csvWrite.print("," + data);
         }
       csvWrite.println();
       String picAddress = info.get("pic");
       info.close();
       if (picAddress.length() == 32) {
         ReadableByteChannel url =
             Channels.newChannel(
                 new URL(
                         "http://"
                             + Configure.webserverAddress
                             + "/"
                             + Configure.picDirectory
                             + picAddress.substring(0, picAddress.length() - 5)
                             + "/"
                             + picAddress.substring(picAddress.length() - 5)
                             + ".jpg")
                     .openStream());
         FileOutputStream outStream =
             new FileOutputStream(picDirectory.getPath() + "/" + id[i] + ".jpg");
         FileChannel out = outStream.getChannel();
         ByteBuffer buffer = ByteBuffer.allocate(10000);
         while (url.read(buffer) != -1) {
           buffer.flip();
           out.write(buffer);
           buffer.clear();
         }
         out.close();
         outStream.close();
         url.close();
       }
     }
     csvWrite.close();
     progressBar.setValue(100);
     finish();
   } catch (Exception e) {
     JOptionPane.showMessageDialog(Port.this, "导出失败!", "错误", JOptionPane.ERROR_MESSAGE);
     dispose();
   }
 }
Exemplo n.º 2
0
 /**
  * Writes this DDSImage to the specified file name.
  *
  * @param file File object to write to
  * @throws java.io.IOException if an I/O exception occurred
  */
 public void write(File file) throws IOException {
   FileOutputStream stream = new FileOutputStream(file);
   write(stream);
   stream.close();
 }