package handlers.files;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import common.ClientServerProtocol;
import common.files.SerializableFile;
import connection.ClientConnection;
import files.IndexedFile;
import handlers.AbstractServerHandler;
import static main.ServerMain.*;
public class GetInfoHandler extends AbstractServerHandler
{
public void execute(ClientConnection connection, ObjectInputStream is,
ObjectOutputStream os) throws IOException, ClassNotFoundException
{
SerializableFile file = (SerializableFile) is.readObject();
IndexedFile indexedFile = getFileManager().retrieveIndexedFile(file);
os.write(ClientServerProtocol.PROTOCOL_FILES);
if (indexedFile == null)
{
os.write(ClientServerProtocol.Files.OP_INVALID_FILE);
os.writeObject(file);
}
else
{
os.write(ClientServerProtocol.Files.OP_FILE_INFO);
os.writeObject(file);
os.writeLong(indexedFile.getChunkLength());
}
}
}