src/main/java/me/dirolgaming/safebac/MetricsLite.java
/**
     * Sends the data to the bStats server.
     *
     * @param data The data to send.
     * @throws Exception If the request failed.
     */
Sends the data to the bStats server.
@param data The data to send.
@throws Exception If the request failed.
Sends the data to the bStats server . @param data The data to send . @throws Exception If the request failed .
private static void sendData(JsonObject data) throws Exception {
        if (data == null) {
            throw new IllegalArgumentException("Data cannot be null");
        }
        HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
        byte[] compressedData = compress(data.toString());
        connection.setRequestMethod("POST");
        connection.addRequestProperty("Accept", "application/json");
        connection.addRequestProperty("Connection", "close");
        connection.addRequestProperty("Content-Encoding", "gzip"); 
        connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
        connection.setRequestProperty("Content-Type", "application/json"); 
        connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
        connection.setDoOutput(true);
        DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
        outputStream.write(compressedData);
        outputStream.flush();
        outputStream.close();
        connection.getInputStream().close(); 
    }
private static void sendData ( JsonObject data ) throws Exception { if ( data == null ) { throw new IllegalArgumentException ( "Data cannot be null" ) ; } HttpsURLConnection connection = ( HttpsURLConnection ) new URL ( URL ) . openConnection ( ) ; byte [ ] compressedData = compress ( data . toString ( ) ) ; connection . setRequestMethod ( "POST" ) ; connection . addRequestProperty ( "Accept" , "application/json" ) ; connection . addRequestProperty ( "Connection" , "close" ) ; connection . addRequestProperty ( "Content-Encoding" , "gzip" ) ; connection . addRequestProperty ( "Content-Length" , String . valueOf ( compressedData . length ) ) ; connection . setRequestProperty ( "Content-Type" , "application/json" ) ; connection . setRequestProperty ( "User-Agent" , "MC-Server/" + B_STATS_VERSION ) ; connection . setDoOutput ( true ) ; DataOutputStream outputStream = new DataOutputStream ( connection . getOutputStream ( ) ) ; outputStream . write ( compressedData ) ; outputStream . flush ( ) ; outputStream . close ( ) ; connection . getInputStream ( ) . close ( ) ; }
Sends the data to the bStats server.
Sends the data to the bStats server .
// Compress the data to save bandwidth // Add headers // We gzip our request // We send our data in JSON format // Send data // We don't care about the response - Just send our data :)