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.OutputStreamOutput stream based onOutputStreamfor 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 booleancloseStreamprotected longcurrentPosprivate java.lang.BooleanlocalHighPrecisionprivate ByteBuffernumBufferprotected java.io.OutputStreamoutputStream
-
Constructor Summary
Constructors Constructor Description HighPrecisionOutputStream(java.io.OutputStream outputStream)Creates a newHighPrecisionOutputStreaminstance based onOutputStreaminstance.HighPrecisionOutputStream(java.io.OutputStream outputStream, boolean localHighPrecision)Creates a newHighPrecisionOutputStreaminstance based onOutputStreaminstance and precision setting value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassignBytes(byte[] bytes, int count)voidclose()voidflush()longgetCurrentPos()Gets current output stream position.static booleangetHighPrecision()Gets global high precision setting.booleangetLocalHighPrecision()Gets local high precision setting.java.io.OutputStreamgetOutputStream()Gets internalOutputStream.booleanisCloseStream()Returns true, if internalOutputStreamhave to be closed afterclose()call, false otherwise.voidreset()SeeByteArrayOutputStream.reset().voidsetCloseStream(boolean closeStream)Sets internalOutputStreamto be closed afterclose().static voidsetHighPrecision(boolean value)Sets global high precision setting for allHighPrecisionOutputStreaminstances.voidsetLocalHighPrecision(boolean value)Sets local high precision setting for theHighPrecisionOutputStream.voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwriteByte(byte value)SeeOutputStream.write(int).TwriteByte(int value)Writes byte to internalOutputStream.TwriteBytes(byte[] b)Seewrite(byte[]).TwriteBytes(byte[] b, int off, int len)TwriteDouble(double value)Writes double to internalOutputStreamin ISO format.TwriteDouble(double value, boolean highPrecision)Writes double to internalOutputStreamin ISO format.TwriteFloat(float value)Writes float to internalOutputStreamin ISO format.TwriteFloat(float value, boolean highPrecision)Writes float to internalOutputStreamin ISO format.TwriteFloats(float[] value)Writes float array to internalOutputStreamin ISO format.TwriteInteger(int value)Writes int to internalOutputStreamin ISO format.TwriteLong(long value)Writes long to internalOutputStreamin ISO format.TwriteNewLine()Writes new line to internalOutputStream.TwriteSpace()Writes space to internalOutputStream.TwriteString(java.lang.String value)WritesStringto internalOutputStreamin 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 newHighPrecisionOutputStreaminstance based onOutputStreaminstance.- Parameters:
outputStream- theHighPrecisionOutputStreaminstance.
-
HighPrecisionOutputStream
public HighPrecisionOutputStream(java.io.OutputStream outputStream, boolean localHighPrecision)Creates a newHighPrecisionOutputStreaminstance based onOutputStreaminstance and precision setting value.- Parameters:
outputStream- theOutputStreaminstance.localHighPrecision- If true, all float and double values will be written with high precision. GlobalByteUtils.HighPrecisionsetting 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 allHighPrecisionOutputStreaminstances.- Parameters:
value- if true, all floats and double will be written with high precision in allHighPrecisionOutputStreaminstances.
-
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.HighPrecisionsetting 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:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
writeByte
public void writeByte(byte value)
SeeOutputStream.write(int).- Parameters:
value- byte to write.- Throws:
IOException- ifIOExceptionoccurs.
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
writeLong
public T writeLong(long value)
Writes long to internalOutputStreamin ISO format.- Parameters:
value- value to write.- Returns:
- this stream as passed generic stream.
-
writeInteger
public T writeInteger(int value)
Writes int to internalOutputStreamin ISO format.- Parameters:
value- value to write.- Returns:
- this stream as passed generic stream.
-
writeFloat
public T writeFloat(float value)
Writes float to internalOutputStreamin 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 internalOutputStreamin 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 internalOutputStreamin ISO format.- Parameters:
value- float array to write.- Returns:
- this stream as passed generic stream.
-
writeDouble
public T writeDouble(double value)
Writes double to internalOutputStreamin 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 internalOutputStreamin 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)
WritesStringto internalOutputStreamin 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- ifIOExceptionis 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- ifIOExceptionis 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 internalOutputStreamhave 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 internalOutputStreamto 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 internalHighPrecisionOutputStreamis not aByteArrayOutputStreaminstance.
-
-