/usr/share/perl5/Plucene/Store/OutputStream.pm is in libplucene-perl 1.25-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | package Plucene::Store::OutputStream;
=head1 NAME
Plucene::Store::OutputStream - a random-access output stream
=head1 SYNOPSIS
# isa Plucene::Store::InputStream
=head1 DESCRIPTION
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.
=head1 METHODS
=cut
use strict;
use warnings;
no warnings 'uninitialized';
use Encode qw(encode);
=head2 new
Create a new Plucene::Store::OutputStream
=cut
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] }
=head2 clone
Clone this
=cut
sub clone {
my $orig = shift;
my $clone = $orig->new($orig->[1]);
CORE::seek($clone->[0], CORE::tell($orig->[0]), 0);
return $clone;
}
=head2 fh / read / seek / tell / getc / print / eof / close
File operations
=cut
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] }
=head2 write_byte
This will write a single byte.
=cut
sub write_byte {
local $\;
CORE::print { $_[0]->[0] } $_[1];
}
=head2 write_int
This will write an int as four bytes.
=cut
sub write_int {
local $\;
CORE::print { $_[0]->[0] } pack("N", $_[1]);
}
=head2 write_vint
This will write an int in a variable length format.
=cut
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;
}
=head2 write_long
This will write a long as eight bytes.
=cut
sub write_long {
local $\;
CORE::print { $_[0]->[0] }
pack("NN", 0xffffffff & ($_[1] >> 32), 0xffffffff & $_[1]);
}
=head2 write_vlong
This will write a long in variable length format.
=cut
*write_vlong = *write_vint;
=head2 write_string
This will write a string.
=cut
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;
|