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;
Stop searching for code, let great code find you!  Add Codota to your java IDE