summaryrefslogtreecommitdiff
path: root/src/ByteArrayDiskWriter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/ByteArrayDiskWriter.cc')
-rw-r--r--src/ByteArrayDiskWriter.cc22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc
index dfc94ede..e51d500b 100644
--- a/src/ByteArrayDiskWriter.cc
+++ b/src/ByteArrayDiskWriter.cc
@@ -20,6 +20,7 @@
*/
/* copyright --> */
#include "ByteArrayDiskWriter.h"
+#include "Util.h"
ByteArrayDiskWriter::ByteArrayDiskWriter():buf(NULL) {
}
@@ -65,16 +66,23 @@ void ByteArrayDiskWriter::openExistingFile(string filename) {
void ByteArrayDiskWriter::writeData(const char* data, int dataLength, long long int position) {
if(bufLength+dataLength >= maxBufLength) {
- expandBuffer(bufLength+dataLength);
+ maxBufLength = Util::expandBuffer(&buf, bufLength, bufLength+dataLength);
}
memcpy(buf+bufLength, data, dataLength);
bufLength += dataLength;
}
-void ByteArrayDiskWriter::expandBuffer(int newSize) {
- char* newbuf = new char[newSize];
- memcpy(newbuf, buf, bufLength);
- delete [] buf;
- buf = newbuf;
- maxBufLength = newSize;
+int ByteArrayDiskWriter::readData(char* data, int len, long long int position) {
+ if(position >= bufLength) {
+ return 0;
+ }
+ int readLength;
+ if(position+len <= bufLength) {
+ readLength = len;
+ } else {
+ readLength = bufLength-position;
+ }
+ memcpy(data, buf+position, readLength);
+ return readLength;
}
+