blob: 45b200db763f6bb768061a12b62d4c935a6e4d8a [file] [log] [blame]
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*
*************************************************************/
#include <string.h>
#include <stdlib.h>
#include "hstream.h"
HStream::HStream() : size(0), pos(0)
{
seq = 0;
}
HStream::~HStream()
{
if( seq )
free( seq );
}
void HStream::addData( const byte *buf, int aToAdd)
{
seq = (byte *)realloc( seq, size + aToAdd );
memcpy( seq + size, buf, aToAdd );
size += aToAdd;
}
int HStream::readBytes(byte * buf, int aToRead)
{
if (aToRead >= (size - pos))
aToRead = size - pos;
for (int i = 0; i < aToRead; i++)
buf[i] = seq[pos++];
return aToRead;
}
int HStream::skipBytes(int aToSkip)
{
if (aToSkip >= (size - pos))
aToSkip = size - pos;
pos += aToSkip;
return aToSkip;
}
int HStream::available()
{
return size - pos;
}
void HStream::closeInput()
{
}