Package com.itextpdf.io.source
Class HighPrecisionOutputStream<T extends java.io.OutputStream>
- java.lang.Object
-
- java.io.OutputStream
-
- com.itextpdf.io.source.HighPrecisionOutputStream<T>
-
- Type Parameters:
T
-OutputStream
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
- Direct Known Subclasses:
PdfOutputStream
public class HighPrecisionOutputStream<T extends java.io.OutputStream> extends java.io.OutputStream
Output stream based onOutputStream
for which it is possible to set high precision in order to write all floats and doubles with high precision.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
closeStream
protected long
currentPos
private java.lang.Boolean
localHighPrecision
private ByteBuffer
numBuffer
protected java.io.OutputStream
outputStream
-
Constructor Summary
Constructors Constructor Description HighPrecisionOutputStream(java.io.OutputStream outputStream)
Creates a newHighPrecisionOutputStream
instance based onOutputStream
instance.HighPrecisionOutputStream(java.io.OutputStream outputStream, boolean localHighPrecision)
Creates a newHighPrecisionOutputStream
instance based onOutputStream
instance and precision setting value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assignBytes(byte[] bytes, int count)
void
close()
void
flush()
long
getCurrentPos()
Gets current output stream position.static boolean
getHighPrecision()
Gets global high precision setting.boolean
getLocalHighPrecision()
Gets local high precision setting.java.io.OutputStream
getOutputStream()
Gets internalOutputStream
.boolean
isCloseStream()
Returns true, if internalOutputStream
have to be closed afterclose()
call, false otherwise.void
reset()
SeeByteArrayOutputStream.reset()
.void
setCloseStream(boolean closeStream)
Sets internalOutputStream
to be closed afterclose()
.static void
setHighPrecision(boolean value)
Sets global high precision setting for allHighPrecisionOutputStream
instances.void
setLocalHighPrecision(boolean value)
Sets local high precision setting for theHighPrecisionOutputStream
.void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
void
writeByte(byte value)
SeeOutputStream.write(int)
.T
writeByte(int value)
Writes byte to internalOutputStream
.T
writeBytes(byte[] b)
Seewrite(byte[])
.T
writeBytes(byte[] b, int off, int len)
T
writeDouble(double value)
Writes double to internalOutputStream
in ISO format.T
writeDouble(double value, boolean highPrecision)
Writes double to internalOutputStream
in ISO format.T
writeFloat(float value)
Writes float to internalOutputStream
in ISO format.T
writeFloat(float value, boolean highPrecision)
Writes float to internalOutputStream
in ISO format.T
writeFloats(float[] value)
Writes float array to internalOutputStream
in ISO format.T
writeInteger(int value)
Writes int to internalOutputStream
in ISO format.T
writeLong(long value)
Writes long to internalOutputStream
in ISO format.T
writeNewLine()
Writes new line to internalOutputStream
.T
writeSpace()
Writes space to internalOutputStream
.T
writeString(java.lang.String value)
WritesString
to internalOutputStream
in ISO format.
-
-
-
Field Detail
-
numBuffer
private final ByteBuffer numBuffer
-
localHighPrecision
private java.lang.Boolean localHighPrecision
-
outputStream
protected java.io.OutputStream outputStream
-
currentPos
protected long currentPos
-
closeStream
protected boolean closeStream
-
-
Constructor Detail
-
HighPrecisionOutputStream
public HighPrecisionOutputStream(java.io.OutputStream outputStream)
Creates a newHighPrecisionOutputStream
instance based onOutputStream
instance.- Parameters:
outputStream
- theHighPrecisionOutputStream
instance.
-
HighPrecisionOutputStream
public HighPrecisionOutputStream(java.io.OutputStream outputStream, boolean localHighPrecision)
Creates a newHighPrecisionOutputStream
instance based onOutputStream
instance and precision setting value.- Parameters:
outputStream
- theOutputStream
instance.localHighPrecision
- If true, all float and double values will be written with high precision. GlobalByteUtils.HighPrecision
setting will be overridden by this one.
-
-
Method Detail
-
getHighPrecision
public static boolean getHighPrecision()
Gets global high precision setting.- Returns:
- global high precision setting.
-
setHighPrecision
public static void setHighPrecision(boolean value)
Sets global high precision setting for allHighPrecisionOutputStream
instances.- Parameters:
value
- if true, all floats and double will be written with high precision in allHighPrecisionOutputStream
instances.
-
getLocalHighPrecision
public boolean getLocalHighPrecision()
Gets local high precision setting.- Returns:
- local high precision setting.
-
setLocalHighPrecision
public void setLocalHighPrecision(boolean value)
Sets local high precision setting for theHighPrecisionOutputStream
. GlobalByteUtils.HighPrecision
setting will be overridden by this one.- Parameters:
value
- if true, all floats and double will be written with high precision in the underlyingHighPrecisionOutputStream
.
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
writeByte
public void writeByte(byte value)
SeeOutputStream.write(int)
.- Parameters:
value
- byte to write.- Throws:
IOException
- ifIOException
occurs.
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
writeLong
public T writeLong(long value)
Writes long to internalOutputStream
in ISO format.- Parameters:
value
- value to write.- Returns:
- this stream as passed generic stream.
-
writeInteger
public T writeInteger(int value)
Writes int to internalOutputStream
in ISO format.- Parameters:
value
- value to write.- Returns:
- this stream as passed generic stream.
-
writeFloat
public T writeFloat(float value)
Writes float to internalOutputStream
in ISO format.- Parameters:
value
- value to write.- Returns:
- this stream as passed generic stream.
-
writeFloat
public T writeFloat(float value, boolean highPrecision)
Writes float to internalOutputStream
in ISO format.- Parameters:
value
- value to write.highPrecision
- If true, float value will be written with high precision.- Returns:
- this stream as passed generic stream.
-
writeFloats
public T writeFloats(float[] value)
Writes float array to internalOutputStream
in ISO format.- Parameters:
value
- float array to write.- Returns:
- this stream as passed generic stream.
-
writeDouble
public T writeDouble(double value)
Writes double to internalOutputStream
in ISO format.- Parameters:
value
- value to write.- Returns:
- this stream as passed generic stream.
-
writeDouble
public T writeDouble(double value, boolean highPrecision)
Writes double to internalOutputStream
in ISO format.- Parameters:
value
- value to write.highPrecision
- If true, double value will be written with high precision.- Returns:
- this stream as passed generic stream.
-
writeByte
public T writeByte(int value)
Writes byte to internalOutputStream
.- Parameters:
value
- value to write.- Returns:
- this stream as passed generic stream.
-
writeSpace
public T writeSpace()
Writes space to internalOutputStream
.- Returns:
- this stream as passed generic stream.
-
writeNewLine
public T writeNewLine()
Writes new line to internalOutputStream
.- Returns:
- this stream as passed generic stream.
-
writeString
public T writeString(java.lang.String value)
WritesString
to internalOutputStream
in ISO format.- Parameters:
value
- string to write.- Returns:
- this stream as passed generic stream.
-
writeBytes
public T writeBytes(byte[] b)
Seewrite(byte[])
.- Parameters:
b
- byte array to write.- Returns:
- this stream as passed generic stream.
- Throws:
IOException
- ifIOException
is thrown.
-
writeBytes
public T writeBytes(byte[] b, int off, int len)
- Parameters:
b
- the data to write.off
- the start offset in the data.len
- the number of bytes to write.- Returns:
- this stream as passed generic stream.
- Throws:
IOException
- ifIOException
is thrown.
-
getCurrentPos
public long getCurrentPos()
Gets current output stream position.- Returns:
- current output stream position.
-
getOutputStream
public java.io.OutputStream getOutputStream()
Gets internalOutputStream
.- Returns:
- internal
OutputStream
.
-
isCloseStream
public boolean isCloseStream()
Returns true, if internalOutputStream
have to be closed afterclose()
call, false otherwise.- Returns:
- true if stream needs to be closed, false if it's done manually.
-
setCloseStream
public void setCloseStream(boolean closeStream)
Sets internalOutputStream
to be closed afterclose()
.- Parameters:
closeStream
- true if stream needs to be closed, false if it's done manually.
-
assignBytes
public void assignBytes(byte[] bytes, int count)
- Parameters:
bytes
- bytes to assign.count
- number of bytes to assign.
-
reset
public void reset()
SeeByteArrayOutputStream.reset()
.- Throws:
IOException
- if internalHighPrecisionOutputStream
is not aByteArrayOutputStream
instance.
-
-