| Plucene documentation | Contained in the Plucene distribution. |
Plucene::Store::OutputStream - a random-access output stream
# isa Plucene::Store::InputStream
This is an abstract class for output to a file in a Directory. A random-access output stream. Used for all Plucene index output operations.
Create a new Plucene::Store::OutputStream
Clone this
File operations
This will write a single byte.
This will write an int as four bytes.
This will write an int in a variable length format.
This will write a long as eight bytes.
This will write a long in variable length format.
This will write a string.
| Plucene documentation | Contained in the Plucene distribution. |
package Plucene::Store::OutputStream;
use strict; use warnings; no warnings 'uninitialized'; use Encode qw(encode);
sub new { my ($self, $filename) = @_; $self = ref $self || $self; open my $fh, '>', $filename or die "$self cannot open $filename for writing: $!"; binmode $fh; bless [ $fh, $filename ], $self; } sub DESTROY { CORE::close $_[0]->[0] }
sub clone { my $orig = shift; my $clone = $orig->new($orig->[1]); CORE::seek($clone->[0], CORE::tell($orig->[0]), 0); return $clone; }
use Carp 'croak'; sub fh { croak "OutputStream fh called" } sub read { croak "OutputStream read called" } sub seek { CORE::seek $_[0]->[0], $_[1], $_[2] } sub tell { CORE::tell $_[0]->[0] } sub getc { croak "OutputStream getc called" } sub print { local $\; my $fh = shift->[0]; CORE::print $fh @_ } sub eof { CORE::eof $_[0]->[0] } sub close { CORE::close $_[0]->[0] }
sub write_byte { local $\; CORE::print { $_[0]->[0] } $_[1]; }
sub write_int { local $\; CORE::print { $_[0]->[0] } pack("N", $_[1]); }
sub write_vint { local $\; use bytes; my $i = $_[1]; my $txt; while ($i & ~0x7f) { $txt .= chr($i | 0x80); $i >>= 7; } $txt .= chr($i); CORE::print { $_[0]->[0] } $txt; }
sub write_long { local $\; CORE::print { $_[0]->[0] } pack("NN", 0xffffffff & ($_[1] >> 32), 0xffffffff & $_[1]); }
*write_vlong = *write_vint;
sub write_string { local $\; my $s = $_[1]; $s = encode("utf8", $s) if $s =~ /[^\x00-\x7f]/; $_[0]->write_vint(length $s); CORE::print { $_[0]->[0] } $s; } 1;