Code example for ProtocolException

    public OutputStream getOutputStream() throws IOException {
        if (!doOutput) {
            throw new ProtocolException("Must set doOutput");
        // you can't write after you read 
        if (sentRequest) {
            throw new ProtocolException("Can't write after you read");
        if (os != null) {
            return os;
        // they are requesting a stream to write to. This implies a POST method 
        if (method == GET) {
            method = POST;
Connect your IDE to all the code out there  Get Codota for Java