@Override
    public boolean writeOperation(SocketChannel s, ByteBuffer buffer) throws IOException {
        buffer.clear();
        Main.state = ServerState.SYNCHRONIZING;
        if(ido != null){
            buffer.put(HexConverter.toByte(Main.ID));
            buffer.putInt(514);
            buffer.put(HexConverter.toByte(getJobID()));
            buffer.put(Protocol.SYNC_LOCAL_INDEX.getValue());
            buffer.put(command);
            buffer.put(MetaDataComposer.decompose(ido));
            buffer.put(LAST_INDEX);
            buffer.rewind();
            while(buffer.hasRemaining())
                s.write(buffer);
            buffer.clear();
            setFinished(true);
            Main.state = ServerState.IDLE;
            buffer.clear();
            return true;
        }else{
            if(localIndexCopy.isEmpty()){
                setFinished(true);
                Main.state = ServerState.IDLE;
                return true;
            }
            buffer.put(HexConverter.toByte(Main.ID));
            buffer.putInt(8176);
            buffer.put(HexConverter.toByte(getJobID()));
            buffer.put(Protocol.SYNC_LOCAL_INDEX.getValue());
            int counter = 15;
            while(counter > 0){
                buffer.put(command);
                buffer.put(MetaDataComposer.decompose(localIndexCopy.get(outerIndex).get(innerIndex)));
                if(innerIndex+1 >= localIndexCopy.get(outerIndex).size()){
                    innerIndex = 0;
                    outerIndex++;
                }else{
                    innerIndex++;
                }
                if(outerIndex == localIndexCopy.size()){
                    buffer.put(LAST_INDEX);
                    setFinished(true);
                    Main.state = ServerState.IDLE;
                    break;
                }
                counter--;
                
                if(counter == 0){
                    buffer.put(LAST_INDEX);
                }else{
                    buffer.put(NOT_LAST_INDEX);
                }
            }
            buffer.rewind();
            while(buffer.hasRemaining())
                s.write(buffer);
            buffer.clear();
            if(isFinished())
                return true;
            else
                return false;
        }
    }