private void sendFile(String fileName, int startByte)
          throws FileNotFoundException, IOException, ClassNotFoundException,
          SQLException {
            
            // Sentinel set to false by default, only sets to true if client
            // can recieve the requested file
            Boolean cont = false;
            
            String[] f = fileName.split("/");
            
            StringBuilder s = new StringBuilder();
            
            // Create actual name of the file and remove version information
            for (int i = 2; i < f.length; i++) {
                s.append(f[i]);
                if (i < f.length-1)
                    s.append("/");
            }
            
            // Check if user is allowed to access the file and it exists
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = (Connection) DriverManager.getConnection(
                    "jdbc:mysql://" + MYSQL_HOST + "/" + MYSQL_DB,
                    MYSQL_USER, MYSQL_PASS);
            Statement stmt = (Statement) conn.createStatement();
            
            // Select all files which are younger or equal to the time
            // of the latest update and belong to the client game.
            String query = "SELECT f.comit_id, f.filename, c.id, c.comit_hash"
                    + " FROM `fils` f, comits c WHERE f.comit_id IN"
                    + " (SELECT id FROM comits WHERE repository_id='" + gameId
                    + "' AND time<='" + time + "') AND f.comit_id=c.id";
            ResultSet rs = stmt.executeQuery(query);
            String comit = null;
            time = null;
            // Iterate through all retrieved file data
            while (rs.next()) {
                String comit_hash = rs.getString("comit_hash");
                String fName = rs.getString("fileName");
                // Check if a file with the particular version exists and
                // is avaialable to the client
                if (comit_hash.equals(f[0]) && s.toString().equals(fName)) {
                    cont = true;
                    break;
                }
            }
            
            // Send a message accordingly
            JSONObject reply = new JSONObject();
            if (!cont)
                reply.put("message", "fileDoesNotExist");
            else
                reply.put("message", "fileExists");
            
            bufferedwriter.write(reply.toJSONString() + "\r\n");
            bufferedwriter.flush();
            
            if (!cont)
                return;
            
            // Create path for the file
            File file = new File(ROOT + "/" + repository
                    + "/fs/commits/" + fileName);
            
            byte[] buf = new byte[4096];
            int len;
            
            FileInputStream fis = new FileInputStream(file);
            
            // Start from the specified byte in the file
            if (startByte > 0)
                fis.skip(startByte - 1);
            
            // Write byte output to the Output Stream
            while((len=fis.read(buf))!=-1) {
                outputstream.write(buf, 0, len);
                outputstream.flush();
            }
            // Close the file after it has been sent
            fis.close();
        }