setasign\SetaPDF2\Core\Reader

MaxFileReader Class for a file reader respecting the maximum allowed open file handles/descriptors.

File: /SetaPDF v2/Core/Reader/MaxFileReader.php
Old class name (alias): \SetaPDF_Core_Reader_MaxFile

Class hierarchy

Implements

Summary

Properties

$_buffer

protected string AbstractReader::$_buffer = ''

The current buffer

$_filename

protected string FileReader::$_filename = ''

The filename

$_handler

$_length

protected int AbstractReader::$_length = 0

The length of the buffer

$_offset

protected int AbstractReader::$_offset = 0

The offset to the current position

$_pos

public int AbstractReader::$_pos = 0

The current file position

$_sleepPosition

protected int MaxFileReader::$_sleepPosition = 0

The position of the point before sleep() was called

$_sleeping

protected bool MaxFileReader::$_sleeping = true

Defines if the reader is sleeping

$_stream

protected resource StreamReader::$_stream

The stream resource

$_totalLength

The total length


Methods

__construct()

public MaxFileReader::__construct (
string $filename,
?\SetaPDF_Core_Reader_MaxFileHandler $handler = null
)

The constructor.

Parameters
$filename : string
 
$handler : ?\SetaPDF_Core_Reader_MaxFileHandler

The handler to which this instance should be bound and notify when opening closing file handles.

Exceptions

Throws Exception

__destruct()

public StreamReader::__destruct (
void
): void

The destruct method.

See

__sleep()

public MaxFileReader::__sleep (
void
): array

Implementation of the __sleep() method.

Exceptions

Throws \BadMethodCallException

__wakeup()

_closeFile()

protected MaxFileReader::_closeFile (
void
): void

Closes the file handle.

_openFile()

protected MaxFileReader::_openFile (
string $filename
): resource

Opens the file.

Parameters
$filename : string
 

_setFilename()

protected FileReader::_setFilename (
string $filename
): void

Set the filename.

Parameters
$filename : string
 
Exceptions

Throws Exception

_setStream()

protected StreamReader::_setStream (
resource $stream
): void

Set the stream.

Parameters
$stream : resource
 
Exceptions

Throws \InvalidArgumentException

Throws Exception

addOffset()

public AbstractReader::addOffset (
int $offset
): void

Add an offset to the current offset.

Parameters
$offset : int
 
Exceptions

Throws Exception

cleanUp()

public MaxFileReader::cleanUp (
void
): void

Release memory/cylced references.

copyTo()

Copies the complete content to a writer instance.

Parameters
$writer : \SetaPDF_Core_WriteInterface
 
Exceptions

Throws Exception

ensure()

public AbstractReader::ensure (
int $pos,
int $length
): void

Ensures bytes in the buffer with a specific length and location in the file.

Parameters
$pos : int
 
$length : int
 
See

ensureContent()

public AbstractReader::ensureContent (
void
): bool

Make sure that there is at least one character beyond the current offset in the buffer.

getBuffer()

public AbstractReader::getBuffer (
bool $atOffset = true
): string

Returns the current buffer.

Parameters
$atOffset : bool
 

getByte()

public AbstractReader::getByte (
int $pos = null
): string|bool

Gets a byte at a specific position.

If the position is invalid the method will return false.

If non position is set $this->_offset will used.

Parameters
$pos : int
 

getFilename()

public FileReader::getFilename (
void
): string

Returns the filename.

getHandler()

Returns the handler instance.

Parameters
$check : bool
 

getLength()

public AbstractReader::getLength (
bool $atOffset = false
): int

Returns the byte length of the buffer.

Parameters
$atOffset : bool
 

getOffset()

public AbstractReader::getOffset (
void
): int

Returns the current offset of the current position.

getPos()

public AbstractReader::getPos (
void
): int

Get the current position of the pointer.

getStream()

public StreamReader::getStream (
void
): resource

Returns the stream.

getTotalLength()

public MaxFileReader::getTotalLength (
void
): int

Gets the total available length.

Exceptions

Throws Exception

increaseLength()

public MaxFileReader::increaseLength (
int $minLength = 100
): bool

Forcefully read more data into the buffer.

Parameters
$minLength : int
 
Exceptions

Throws Exception

isSleeping()

public MaxFileReader::isSleeping (
void
): bool

Checks if the reader is sleeping.

readByte()

public AbstractReader::readByte (
int $pos = null
): string|bool

Returns a byte at a specific position, returns it and set the offset to the next byte position.

If the position is invalid the method will return false.

If non position is set $this->_offset will used.

Parameters
$pos : int
 

readBytes()

public AbstractReader::readBytes (
int $length,
int $pos = null
): string|bool

Get a specific byte count from the current or at a specific offset position and set the internal pointer to the next byte.

If the position is invalid the method will return false.

If non position is set $this->_offset will used.

Parameters
$length : int
 
$pos : int
 

readLine()

public AbstractReader::readLine (
int $length = 1024
): string|false

Read a line from the current position.

Parameters
$length : int
 
Exceptions

Throws Exception

reset()

public MaxFileReader::reset (
?int $pos = 0,
int $length = 200
): void

Resets the buffer to a specific position and reread the buffer with the given length.

If the $pos is negative the start buffer position will be the $pos'th position from the end of the file.

If the $pos is negative and the absolute value is bigger then the totalLength of the file $pos will set to zero.

Parameters
$pos : ?int

Start position of the new buffer

$length : int

Length of the new buffer. Mustn't be negative

Exceptions

Throws Exception

setHandler()

Set a handler.

Parameters
$handler : ?\SetaPDF_Core_Reader_MaxFileHandler
 

setOffset()

public AbstractReader::setOffset (
int $offset
): void

Set the offset position.

Parameters
$offset : int
 
Exceptions

Throws Exception

sleep()

public MaxFileReader::sleep (
void
): void

Set the reader into sleep-state.

In this implementation the file handles will be closed to avoid reaching the limit of open file handles.

See

wakeUp()

public MaxFileReader::wakeUp (
void
): bool

Wake up the reader if it is in sleep-state.

Re-open the file handle.

Exceptions

Throws Exception

See