package org.wikiwebserver.distribute.util;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.wikiwebserver.distribute.interfaces.Persistable;

public class FileDetails implements Persistable {
	
	private static final long serialVersionUID = 1L;
	
	private String name;
	private boolean isDirectory;
	private long lastModified, length;
	
	public FileDetails() {
		
	}
	
	public FileDetails(String name, boolean isDirectory, long lastModified, long length) {
		this.name = name;
		this.isDirectory = isDirectory;
		this.lastModified = lastModified;
		this.length = length;
	}

	public String getName() {
		return this.name;
	}

	public boolean isDirectory() {
		return this.isDirectory;
	}

	public long getLastModified() {
		return this.lastModified;
	}

	public long getLength() {
		return this.length;
	}

	public void persist(DataOutputStream dout) throws IOException {

        dout.writeUTF(getName());
        dout.writeBoolean(isDirectory());
        dout.writeLong(getLastModified());
        dout.writeLong(getLength());
	}


	public void resurrect(DataInputStream din) throws IOException {

        this.name = din.readUTF();
        this.isDirectory = din.readBoolean();
        this.lastModified = din.readLong();
        this.length = din.readLong();
	}
}
