001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/methods/ByteArrayRequestEntity.java,v 1.3 2004/05/13 02:26:08 mbecke Exp $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: *
006: * ====================================================================
007: *
008: * Licensed to the Apache Software Foundation (ASF) under one or more
009: * contributor license agreements. See the NOTICE file distributed with
010: * this work for additional information regarding copyright ownership.
011: * The ASF licenses this file to You under the Apache License, Version 2.0
012: * (the "License"); you may not use this file except in compliance with
013: * the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing, software
018: * distributed under the License is distributed on an "AS IS" BASIS,
019: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020: * See the License for the specific language governing permissions and
021: * limitations under the License.
022: * ====================================================================
023: *
024: * This software consists of voluntary contributions made by many
025: * individuals on behalf of the Apache Software Foundation. For more
026: * information on the Apache Software Foundation, please see
027: * <http://www.apache.org/>.
028: *
029: * [Additional notices, if required by prior licensing conditions]
030: *
031: */
032: package org.apache.commons.httpclient.methods;
033:
034: import java.io.IOException;
035: import java.io.OutputStream;
036:
037: /**
038: * A RequestEntity that contains an array of bytes.
039: *
040: * @since 3.0
041: */
042: public class ByteArrayRequestEntity implements RequestEntity {
043:
044: /** The content */
045: private byte[] content;
046:
047: /** The content type */
048: private String contentType;
049:
050: /**
051: * Creates a new entity with the given content.
052: * @param content The content to set.
053: */
054: public ByteArrayRequestEntity(byte[] content) {
055: this (content, null);
056: }
057:
058: /**
059: * Creates a new entity with the given content and content type.
060: * @param content The content to set.
061: * @param contentType The content type to set or <code>null</code>.
062: */
063: public ByteArrayRequestEntity(byte[] content, String contentType) {
064: super ();
065: if (content == null) {
066: throw new IllegalArgumentException(
067: "The content cannot be null");
068: }
069: this .content = content;
070: this .contentType = contentType;
071: }
072:
073: /**
074: * @return <code>true</code>
075: */
076: public boolean isRepeatable() {
077: return true;
078: }
079:
080: /* (non-Javadoc)
081: * @see org.apache.commons.httpclient.methods.RequestEntity#getContentType()
082: */
083: public String getContentType() {
084: return contentType;
085: }
086:
087: /* (non-Javadoc)
088: * @see org.apache.commons.httpclient.RequestEntity#writeRequest(java.io.OutputStream)
089: */
090: public void writeRequest(OutputStream out) throws IOException {
091: out.write(content);
092: }
093:
094: /**
095: * @return The length of the content.
096: */
097: public long getContentLength() {
098: return content.length;
099: }
100:
101: /**
102: * @return Returns the content.
103: */
104: public byte[] getContent() {
105: return content;
106: }
107:
108: }
|