Exemplo n.º 1
1
  protected Header readHeaderFromBuffer(ByteBuffer buffer) throws WWRuntimeException {
    // Read file code - first byte
    int fileCode = buffer.get();
    if (fileCode > 5) {
      String message = Logging.getMessage("SHP.NotADBaseFile", file.getPath());
      Logging.logger().log(java.util.logging.Level.SEVERE, message);
      throw new WWRuntimeException(message);
    }

    // Last update date
    int yy = 0xFF & buffer.get(); // unsigned
    int mm = buffer.get();
    int dd = buffer.get();

    // Number of records
    int numRecords = buffer.getInt();

    // Header struct length
    int headerLength = buffer.getShort();

    // Record length
    int recordLength = buffer.getShort();

    // Assemble header
    Header header = new Header();
    header.fileCode = fileCode;
    Calendar cal = Calendar.getInstance();
    cal.set(1900 + yy, mm - 1, dd);
    header.lastModificationDate = cal.getTime();
    header.numberOfRecords = numRecords;
    header.headerLength = headerLength;
    header.recordLength = recordLength;

    return header;
  }
Exemplo n.º 2
1
  public DBaseFile(InputStream is) {
    if (is == null) {
      String message = Logging.getMessage("nullValue.InputStreamIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.file = null;
    try {
      this.header = this.readHeaderFromStream(is);
      this.fields = this.readFieldsFromBuffer(this.header.fieldsHeaderBuffer);
      this.records = this.readRecordsFromStream(is);
    } catch (Exception e) {
      String message = Logging.getMessage("generic.ExceptionAttemptingToReadFrom", is.toString());
      Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
      throw new WWRuntimeException(message, e);
    }
  }
Exemplo n.º 3
0
  public List<DBaseRecord> getRecords() {
    if (this.records == null && this.getFile() != null) {
      File file = this.getFile();
      try {
        this.records = this.readRecordsFromFile(file);
      } catch (Exception e) {
        String message = Logging.getMessage("SHP.ExceptionAttemptingToReadFile", file.getPath());
        Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
        throw new WWRuntimeException(message, e);
      }
    }

    return this.records;
  }
Exemplo n.º 4
0
  public DBaseFile(File file) {
    if (file == null) {
      String message = Logging.getMessage("nullValue.FileIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    this.file = file;
    try {
      this.header = this.readHeaderFromFile(file);
      this.fields = this.readFieldsFromBuffer(this.header.fieldsHeaderBuffer);
      // Delay records loading until getRecords() is called.
    } catch (Exception e) {
      String message = Logging.getMessage("SHP.ExceptionAttemptingToReadFile", file.getPath());
      Logging.logger().log(java.util.logging.Level.SEVERE, message, e);
      throw new WWRuntimeException(message, e);
    }
  }