@Override
    public void run() {


        System.out.println("WRITE SERVER-WRITER: ");
        String filename = "";
        int bytesWritten = 0;

        buf.flip();
        String encoding = System.getProperty("file.encoding");
        filename = Charset.forName(encoding).decode(buf).toString();

        logger.info("Server: sending file " + filename);
        logger.info("Server started sending data ...");


        RandomAccessFile fromFile = null;
        int count = 0;

        try {
            fromFile = new RandomAccessFile(name + "/" + filename, "rw");
            FileChannel fc = fromFile.getChannel();

//              Daca se trimite primul pachet cu lungimea fisierului din nush ce motive mistice se pierde
//           primul pachet din fisier...

//            buf.clear();
//            buf.putLong(fromFile.length());
//            buf.flip();
//            while (socketChannel.write(buf) < 0){
//
//            }

            buf.clear();
            while (fc.read(buf) >= 0 || buf.position() > 0) {

                buf.flip();

                bytesWritten = socketChannel.write(buf);
                count += bytesWritten;
                buf.clear();

            }

            logger.info("Server done sending data");

            fc.close();
            fromFile.close();
            socketChannel.close();
            buf.clear();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }