예제 #1
0
 private void deflate(String tmpDir, String path) {
   String tmpFile = "tmp-" + Utils.timestamp() + ".zip";
   try {
     ZipFile zipFile = new ZipFile(tmpFile);
     ZipParameters parameters = new ZipParameters();
     parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
     parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
     parameters.setIncludeRootFolder(false);
     zipFile.addFolder(tmpDir, parameters);
   } catch (Exception e) {
     e.printStackTrace();
     return;
   }
   File from = null;
   File to = null;
   try {
     File target = new File(path);
     if (target.exists()) FileUtils.forceDelete(target);
     from = new File(tmpFile);
     to = new File(path);
     FileUtils.moveFile(from, to);
   } catch (IOException e) {
     Utils.onError(new Error.FileMove(tmpFile, path));
   }
   try {
     FileUtils.deleteDirectory(new File(tmpDir));
   } catch (IOException e) {
     Utils.log("can't delete temporary folder");
   }
 }
  /**
   * Constructs a DBFHeader, read the data from file <br>
   * You need to supply an open file handle to read from
   *
   * @param ff open file handle for read access
   */
  DBFHeader(RandomAccessFile ff) throws tinySQLException {
    try {
      ff.seek(FLAG_INDEX);
      file_type = Utils.fixByte(ff.readByte());

      // get the last update date
      file_update_year = Utils.fixByte(ff.readByte());
      file_update_month = Utils.fixByte(ff.readByte());
      file_update_day = Utils.fixByte(ff.readByte());

      // a byte array to hold little-endian long data
      //
      byte[] b = new byte[4];

      // read that baby in...
      //
      ff.readFully(b);

      // convert the byte array into a long (really a double)
      // 4-7 number of records
      numRecords = (int) Utils.vax_to_long(b);

      // a byte array to hold little-endian short data
      //
      b = new byte[2];

      // get the data position (where it starts in the file)
      // 8-9 Length of header
      ff.readFully(b);
      headerLength = Utils.vax_to_short(b);

      // find out the length of the data portion
      // 10-11 Length of Record
      ff.readFully(b);
      recordLength = Utils.vax_to_short(b);

      // calculate the number of fields
      //
      numFields = (headerLength - 33) / 32;

      // skip the next 20 bytes - looks like this is not needed...
      // ff.skipBytes(20);
      // 12-31 reserved

      Utils.log("HEADER=" + this.toString());

    } catch (Exception e) {
      throw new tinySQLException(e.getMessage());
    }
  }
 /**
  * Constructs a DBFHeader, read the data from file <br>
  * You need to supply an open file handle to read from
  *
  * @param numFields number of Columns
  * @param recordLength sum of all column.size plus 1 byte (delete flag)
  */
 DBFHeader(int numFields, int recordLength) throws tinySQLException {
   this.numFields = numFields;
   this.recordLength = recordLength;
   Utils.log("DBFHeader", "numFields=" + numFields + " recordLength=" + recordLength);
 }