001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027 028package org.apache.http.nio.protocol; 029 030import java.io.IOException; 031import java.nio.ByteBuffer; 032 033import org.apache.http.HttpRequest; 034import org.apache.http.nio.ContentDecoder; 035import org.apache.http.nio.IOControl; 036import org.apache.http.protocol.HttpContext; 037 038class NullRequestConsumer implements HttpAsyncRequestConsumer<Object> { 039 040 private final ByteBuffer buffer; 041 private volatile boolean completed; 042 043 NullRequestConsumer() { 044 super(); 045 this.buffer = ByteBuffer.allocate(2048); 046 } 047 048 @Override 049 public void requestReceived(final HttpRequest request) { 050 } 051 052 @Override 053 public void consumeContent( 054 final ContentDecoder decoder, final IOControl ioctrl) throws IOException { 055 int lastRead; 056 do { 057 this.buffer.clear(); 058 lastRead = decoder.read(this.buffer); 059 } while (lastRead > 0); 060 } 061 062 @Override 063 public void requestCompleted(final HttpContext context) { 064 this.completed = true; 065 } 066 067 @Override 068 public void failed(final Exception ex) { 069 this.completed = true; 070 } 071 072 @Override 073 public Object getResult() { 074 return Boolean.valueOf(this.completed); 075 } 076 077 @Override 078 public Exception getException() { 079 return null; 080 } 081 082 @Override 083 public void close() throws IOException { 084 this.completed = true; 085 } 086 087 @Override 088 public boolean isDone() { 089 return this.completed; 090 } 091 092}