Top Description Inners Fields Constructors Methods
org.python.core.io

public Class UniversalIOWrapper

extends TextIOBase
Class Inheritance
Imports
java.nio.ByteBuffer, java.util.EnumSet, org.python.core.Py, .PyObject, .PyString, .PyTuple

A Buffered text stream in universal newlines mode.
Author
Philip Jenvey

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private EnumSet<UniversalIOWrapper.Newline>
newlineTypes

The Newlines encountered in this file

private boolean
skipNextLF

Whether the next character, if it's an LF, should be skipped (the previous character was a CR)

Inherited from org.python.core.io.TextIOBase:
bufferedIObuilderCHUNK_SIZECR_BYTEinterimBuilderreadahead

Constructor Summary

AccessConstructor and Description
public
UniversalIOWrapper(BufferedIOBase bufferedIO)

Contruct a UniversalIOWrapper wrapping the given BufferedIOBase.

Method Summary

Modifier and TypeMethod and Description
public PyObject
getNewlines()

Overrides org.python.core.io.TextIOBase.getNewlines.

Return the known Newline types, as a PyObject, encountered while reading this file.

public String
read(int
the number of bytes to read
size
)

Overrides org.python.core.io.TextIOBase.read.

Read and return up to size bytes, contained in a String.

public String
readall()

Overrides org.python.core.io.TextIOBase.readall.

Read until EOF.

public String
readline(int
the number of bytes to read
size
)

Overrides org.python.core.io.TextIOBase.readline.

Read until size, newline or EOF.

private int

Returns:

the number of chars written to the destination array
readLoop
(byte[]
the source byte array
src
,
int
starting position in the source array
srcPos
,
char[]
the destination char array
dest
,
int
starting position in the destination array
destPos
,
int
the number of array elements to be copied
length
)

Read and convert the src byte array into the dest char array.

public long
seek(long
a long position value
pos
,
int
an int whence value
whence
)

Overrides org.python.core.io.TextIOBase.seek.

Seek to byte offset pos relative to position indicated by whence.

public long
tell()

Overrides org.python.core.io.TextIOBase.tell.

Return the current stream position.

public int
write(String
a String value
buf
)

Overrides org.python.core.io.TextIOBase.write.

Write the given String to the IO stream.

Inherited from org.python.core.io.TextIOBase:
asInputStreamasOutputStreamatEOFclearReadaheadclosecloseddrainBuilderfilenoflushisattypackReadaheadreadablereadChunkreadChunkreadintotruncatewritable

Field Detail

newlineTypesback to summary
private EnumSet<UniversalIOWrapper.Newline> newlineTypes

The Newlines encountered in this file

skipNextLFback to summary
private boolean skipNextLF

Whether the next character, if it's an LF, should be skipped (the previous character was a CR)

Constructor Detail

UniversalIOWrapperback to summary
public UniversalIOWrapper(BufferedIOBase bufferedIO)

Contruct a UniversalIOWrapper wrapping the given BufferedIOBase.

Method Detail

getNewlinesback to summary
public PyObject getNewlines()

Overrides org.python.core.io.TextIOBase.getNewlines.

Doc from org.python.core.io.TextIOBase.getNewlines.

Return the known Newline types, as a PyObject, encountered while reading this file. Returns None for all modes except universal newline mode.

Returns:PyObject

a PyObject containing all encountered Newlines, or None

Annotations
@Override
readback to summary
public String read(int size)

Overrides org.python.core.io.TextIOBase.read.

Doc from org.python.core.io.TextIOBase.read.

Read and return up to size bytes, contained in a String. Returns an empty String on EOF

Parameters
size:int

the number of bytes to read

Returns:String

a String containing the bytes read

Annotations
@Override
readallback to summary
public String readall()

Overrides org.python.core.io.TextIOBase.readall.

Doc from org.python.core.io.TextIOBase.readall.

Read until EOF.

Returns:String

a String containing the bytes read

Annotations
@Override
readlineback to summary
public String readline(int size)

Overrides org.python.core.io.TextIOBase.readline.

Doc from org.python.core.io.TextIOBase.readline.

Read until size, newline or EOF. Returns an empty string if EOF is hit immediately.

Parameters
size:int

the number of bytes to read

Returns:String

a String containing the bytes read

Annotations
@Override
readLoopback to summary
private int readLoop(byte[] src, int srcPos, char[] dest, int destPos, int length)

Read and convert the src byte array into the dest char array. Converts CR and CRLF to LF. No attempt is made to handle CRLF at EOF; skipNextLF may be toggled true after this method returns.

Parameters
src:byte[]

the source byte array

srcPos:int

starting position in the source array

dest:char[]

the destination char array

destPos:int

starting position in the destination array

length:int

the number of array elements to be copied

Returns:int

the number of chars written to the destination array

seekback to summary
public long seek(long pos, int whence)

Overrides org.python.core.io.TextIOBase.seek.

Doc from org.python.core.io.IOBase.seek.

Seek to byte offset pos relative to position indicated by whence.

Semantics
whence Seek to pos
0 Start of stream (the default).Should be ≥0.
1 Current position + pos Either sign.
2 End of stream + pos Usually ≤0.
Returns the new absolute position.
Parameters
pos:long

a long position value

whence:int

an int whence value

Returns:long

a long position value seeked to

Annotations
@Override
tellback to summary
public long tell()

Overrides org.python.core.io.TextIOBase.tell.

Doc from org.python.core.io.IOBase.tell.

Return the current stream position.

Returns:long

a long position value

Annotations
@Override
writeback to summary
public int write(String buf)

Overrides org.python.core.io.TextIOBase.write.

Doc from org.python.core.io.TextIOBase.write.

Write the given String to the IO stream. Returns the number of characters written.

Parameters
buf:String

a String value

Returns:int

the number of characters written as an int

Annotations
@Override
org.python.core.io back to summary

private final Enum UniversalIOWrapper.Newline

extends Enum<UniversalIOWrapper.Newline>
Class Inheritance

Newline types.

Field Summary

Modifier and TypeField and Description
public static final UniversalIOWrapper.Newline
CR

Carriage return

public static final UniversalIOWrapper.Newline
CRLF

Carriage return line feed

public static final UniversalIOWrapper.Newline
LF

Line feed

private final String
value

The String value

Constructor Summary

AccessConstructor and Description
private
Newline(String
the newline character as a String
value
)

Construct a new Newline.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the newline character as a String
getValue
()

Return the String value of this newline

public static UniversalIOWrapper.Newline
public static UniversalIOWrapper.Newline[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CRback to summary
public static final UniversalIOWrapper.Newline CR

Carriage return

CRLFback to summary
public static final UniversalIOWrapper.Newline CRLF

Carriage return line feed

LFback to summary
public static final UniversalIOWrapper.Newline LF

Line feed

valueback to summary
private final String value

The String value

Constructor Detail

Newlineback to summary
private Newline(String value)

Construct a new Newline.

Parameters
value:String

the newline character as a String

Method Detail

getValueback to summary
public String getValue()

Return the String value of this newline

Returns:String

the newline character as a String

valueOfback to summary
public static UniversalIOWrapper.Newline valueOf(String name)
valuesback to summary
public static UniversalIOWrapper.Newline[] values()