package fi.jyu.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import javax.net.ssl.HttpsURLConnection;

public class CommHelpers {
	
	// Writes a request to a connection
	public static boolean writeRequest(HttpsURLConnection connection, String textBody) {
		try {
			BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
			wr.write(textBody);
			wr.flush();
			wr.close();
				
			return true;
		}
		catch (IOException e) { return false; }
	}
		
	// Reads a response for a given connection and returns it as a string.
	public static String readResponse(HttpsURLConnection connection) {
		try {
			StringBuilder str = new StringBuilder();
				
			BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String line = "";
			while((line = br.readLine()) != null) {
				str.append(line + System.getProperty("line.separator"));
			}
			return str.toString();
		}
		catch (IOException e) { return new String(); }
	}
}

@@ -250,45 +250,8 @@
 %7B%0A%09%0A
-%09// Writes a request to a connection%0A
 %09pub
@@ -567,80 +567,8 @@
 %0A%09%09%0A
-%09// Reads a response for a given connection and returns it as a string.%0A
 %09pub

Update CommHelpers.java