mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
generalize the size() implementation
This commit is contained in:
parent
5e40f1603e
commit
82bf9f7eea
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017 - 2018 Volker Berlin (i-net software)
|
* Copyright 2017 - 2019 Volker Berlin (i-net software)
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -32,6 +32,8 @@ import de.inetsoftware.jwebassembly.wasm.ValueType;
|
|||||||
*/
|
*/
|
||||||
class WasmOutputStream extends FilterOutputStream {
|
class WasmOutputStream extends FilterOutputStream {
|
||||||
|
|
||||||
|
private int count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a in memory stream.
|
* Create a in memory stream.
|
||||||
*/
|
*/
|
||||||
@ -49,6 +51,24 @@ class WasmOutputStream extends FilterOutputStream {
|
|||||||
super( output );
|
super( output );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void write( int b ) throws IOException {
|
||||||
|
out.write( b );
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void write( byte[] b, int off, int len ) throws IOException {
|
||||||
|
out.write( b, off, len );
|
||||||
|
count += len;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a binary operation code.
|
* Write a binary operation code.
|
||||||
*
|
*
|
||||||
@ -245,13 +265,12 @@ class WasmOutputStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The count of bytes in the stream. Work only for in memory stream.
|
* The count of bytes in the stream.
|
||||||
*
|
*
|
||||||
* @return the data size
|
* @return the data size
|
||||||
*/
|
*/
|
||||||
int size() {
|
int size() {
|
||||||
ByteArrayOutputStream baos = (ByteArrayOutputStream)out;
|
return count;
|
||||||
return baos.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -260,5 +279,6 @@ class WasmOutputStream extends FilterOutputStream {
|
|||||||
void reset() {
|
void reset() {
|
||||||
ByteArrayOutputStream baos = (ByteArrayOutputStream)out;
|
ByteArrayOutputStream baos = (ByteArrayOutputStream)out;
|
||||||
baos.reset();
|
baos.reset();
|
||||||
|
count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user