예제 #1
0
  @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    int len = in.readInt();
    byte[] b = new byte[len];

    // read fully
    int done = 0;
    while (done < len) {
      int got = in.read(b, done, len - done);
      if (got < 0) throw new IOException();
      done += got;
    }

    FileSystemProto.Directory proto = FileSystemProto.Directory.parseFrom(b);

    path = proto.getPath();
    lastModified = proto.getLastModified();
    List<FileSystemProto.File> files = proto.getFilesList();
    children = new CacheFileProto[files.size()];
    for (int i = 0; i < files.size(); i++) {
      FileSystemProto.File fp = files.get(i);
      CacheFileProto cf = new CacheFileProto();
      cf.setShortName(fp.getName());
      cf.setDirectory(fp.getIsDirectory());
      cf.setLastModified(fp.getLastModified());
      cf.setLength(fp.getLength());

      children[i] = cf;
    }
  }
예제 #2
0
  @Override
  public void writeExternal(ObjectOutput out) throws IOException {
    FileSystemProto.Directory.Builder dirBuilder = FileSystemProto.Directory.newBuilder();

    dirBuilder.setPath(getPath());
    dirBuilder.setLastModified(getLastModified());

    FileSystemProto.File.Builder fileBuilder = FileSystemProto.File.newBuilder();
    for (CacheFileProto child : children) {
      fileBuilder.clear();
      fileBuilder.setName(child.getShortName());
      fileBuilder.setIsDirectory(child.isDirectory());
      fileBuilder.setLastModified(child.getLastModified());
      fileBuilder.setLength(child.getLength());

      dirBuilder.addFiles(fileBuilder);
    }

    thredds.filesystem.FileSystemProto.Directory dirProto = dirBuilder.build();
    byte[] b = dirProto.toByteArray();

    out.writeInt(b.length);
    out.write(b);
  }