Package handlers.files

Source Code of handlers.files.GetSourcesHandler

package handlers.files;


import handlers.AbstractServerHandler;

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 static main.ServerMain.*;


public class GetSourcesHandler extends AbstractServerHandler
{
  public void execute(ClientConnection connection, ObjectInputStream is,
      ObjectOutputStream os) throws IOException, ClassNotFoundException
  {
    SerializableFile requestedFile = (SerializableFile) is.readObject();
    boolean addClientAsSource = is.readBoolean();

    IndexedFile serverFile = getFileManager().retrieveIndexedFile(requestedFile);

    if (serverFile == null)
    {
      os.write(ClientServerProtocol.PROTOCOL_FILES);
      os.write(ClientServerProtocol.Files.OP_INVALID_FILE);
      os.writeObject(requestedFile);
      return;
    }

    os.write(ClientServerProtocol.PROTOCOL_FILES);
    os.write(ClientServerProtocol.Files.OP_FILE_SOURCES);
    os.writeObject(requestedFile);
    serverFile.serializeStatus(connection.getClientId(), os);

    if (addClientAsSource)
    {
      getFileManager().addSharedFile(requestedFile, connection.getClientId());
    }
  }

}
TOP

Related Classes of handlers.files.GetSourcesHandler

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.