Package scfs.util

Source Code of scfs.util.ExternalizableHashMap

package scfs.util;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.concurrent.ConcurrentHashMap;

import scfs.directoryService.NodeMetadata;

public class ExternalizableHashMap extends ConcurrentHashMap<String, NodeMetadata> implements Externalizable {

  public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(this.size());
    for(Entry<String, NodeMetadata> e : entrySet()){
      out.writeUTF(e.getKey());
      e.getValue().writeExternal(out);
    }
  }

  @Override
  public void readExternal(ObjectInput in) throws IOException,
      ClassNotFoundException {
    int len = in.readInt();
    for(int i = 0; i<len ; i++){
      String key = in.readUTF();
      NodeMetadata m = new NodeMetadata();
      m.readExternal(in);
      this.put(key, m);
    }
  }

}
TOP

Related Classes of scfs.util.ExternalizableHashMap

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.