If you think the Android project Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2014.//fromwww.java2s.com
*
* BaasBox - info@baasbox.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/package com.baasbox.android;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
/**
* Created by Andrea Tortorella on 19/05/14.
*/class FixedByteArrayOutputStream extends OutputStream {
privatebyte[] mData;
privateint mCount;
FixedByteArrayOutputStream(long size){
this((int)size);
}
FixedByteArrayOutputStream(int size){
if (size<0) thrownew IllegalArgumentException("Size cannot be negative");
mData = newbyte[size];
}
@Override
publicvoid write(byte[] buffer) throws IOException {
this.write(buffer,0,buffer.length);
}
@Override
publicvoid write(byte[] buffer, int offset, int count) throws IOException {
if ((offset<0)||(offset>buffer.length)||(count<0)||((offset+count)>buffer.length)||
((offset+count)<0)){
thrownew IndexOutOfBoundsException();
} elseif (count == 0){
return;
} else {
int c = mCount+count;
System.arraycopy(buffer,offset,mData,mCount,count);
mCount=c;
}
}
@Override
publicsynchronizedvoid write(int oneByte) throws IOException {
if (mCount==mData.length){
thrownew IndexOutOfBoundsException("Array index out of bounds");
}
mData[mCount++]=(byte)oneByte;
}
publicsynchronizedvoid writeTo(OutputStream out) throws IOException{
out.write(mData,0,mCount);
}
publicsynchronizedvoid reset(){
mCount = 0;
}
publicsynchronizedbyte[] data(){
return mData;
}
publicsynchronizedbyte[] copy(){
return Arrays.copyOf(mData,mCount);
}
publicsynchronizedint size(){
return mCount;
}
@Override
publicsynchronized String toString() {
returnnew String(mData,0,mCount);
}
publicsynchronized String toString(String charset) throws UnsupportedEncodingException{
returnnew String(mData,0,mCount,charset);
}
@Override
publicvoid close() throws IOException {
}
}