00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef _DECAF_IO_BYTEARRAYOUTPUTSTREAM_H_ 00019 #define _DECAF_IO_BYTEARRAYOUTPUTSTREAM_H_ 00020 00021 #include <decaf/util/Config.h> 00022 00023 #include <decaf/io/OutputStream.h> 00024 #include <decaf/lang/exceptions/IllegalArgumentException.h> 00025 00026 #include <utility> 00027 00028 namespace decaf{ 00029 namespace io{ 00030 00031 class DECAF_API ByteArrayOutputStream: public OutputStream { 00032 private: 00033 00037 unsigned char* buffer; 00038 00042 int bufferSize; 00043 00047 int count; 00048 00049 private: 00050 00051 ByteArrayOutputStream(const ByteArrayOutputStream&); 00052 ByteArrayOutputStream& operator=(const ByteArrayOutputStream&); 00053 00054 public: 00055 00060 ByteArrayOutputStream(); 00061 00071 ByteArrayOutputStream(int bufferSize); 00072 00073 virtual ~ByteArrayOutputStream(); 00074 00083 std::pair<unsigned char*, int> toByteArray() const; 00084 00090 long long size() const; 00091 00096 virtual void reset(); 00097 00102 virtual std::string toString() const; 00103 00109 void writeTo(OutputStream* out) const; 00110 00111 protected: 00112 00113 virtual void doWriteByte(unsigned char value); 00114 00115 virtual void doWriteArrayBounded(const unsigned char* buffer, int size, int offset, int length); 00116 00117 private: 00118 00119 // Expands the buffer if there's not enough room for the needed length. 00120 void checkExpandSize(int needed); 00121 00122 }; 00123 00124 }} 00125 00126 #endif /*_DECAF_IO_BYTEARRAYOUTPUTSTREAM_H_*/
1.6.1