Ignore:
Timestamp:
2013-05-21T14:46:55+12:00 (11 years ago)
Author:
jmt12
Message:

Updating calls to intermediate util functions to the new FileUtils functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/perllib/plugins/ReadTextFile.pm

    r26963 r27377  
    3939use ghtml;
    4040use gsprintf 'gsprintf';
     41use util;
     42use FileUtils;
    4143
    4244use AutoExtractMetadata;
     
    140142    # this should look at the plugin option too...
    141143    $doc_obj->add_utf8_metadata($top_section, "Plugin", "$self->{'plugin_type'}");
    142     $doc_obj->add_utf8_metadata($top_section, "FileSize", &util::file_size($filename_full_path));
     144    $doc_obj->add_utf8_metadata($top_section, "FileSize", &FileUtils::fileSize($filename_full_path));
    143145
    144146    my $plugin_filename_encoding = $self->{'filename_encoding'};
     
    202204    my ($filename, $encoding, $language, $textref) = @_;
    203205
    204     if (!&util::file_canread($filename))
     206    if (!&FileUtils::canRead($filename))
    205207    {
    206208    my $outhandle = $self->{'outhandle'};
     
    213215    # use the util::file_* functions to provide some extra smarts to the open
    214216    # command in order to support protocols like http: or hdfs:
    215     if (!open (FILE, &util::file_openfdcommand($filename, '<')))
     217    my $fh;
     218    if (!&FileUtils::openFileHandle($filename, '<', \$fh))
    216219    {
    217220      gsprintf(STDERR, "ReadTextFile::read_file {ReadTextFile.could_not_open_for_reading} ($!)\n", $filename);
     
    222225    {
    223226      # fast file 'slurp' implementation
    224       sysread(FILE, $$textref, &util::file_size($filename));
     227      sysread($fh, $$textref, &FileUtils::fileSize($filename));
    225228      # the old slow way of reading in a file
    226229      #undef $/;
     
    231234    {
    232235      my $reader = new multiread();
    233       $reader->set_handle ('ReadTextFile::FILE');
     236      $reader->set_handle ($fh);
    234237      $reader->set_encoding ($encoding);
    235238      $reader->read_file ($textref);
     
    243246    $$textref = decode("utf8", $$textref);
    244247
    245     close FILE;
     248    &FileUtils::closeFileHandle($filename, \$fh);
    246249}
    247250
     
    368371    my $best_language = "";
    369372    my $best_encoding = "";
    370    
    371373
    372374    # read in file
    373     if (!open (FILE, &util::file_openfdcommand($filename, '<'))) {
    374     gsprintf(STDERR, "ReadTextFile::get_language_encoding {ReadTextFile.could_not_open_for_reading} ($!)\n", $filename);
    375     # this is a pretty bad error, but try to continue anyway
    376     return ($self->{'default_language'}, $self->{'input_encoding'});
     375    my $fh;
     376    if (!&FileUtils::openFileHandle($filename, '<', \$fh))
     377    {
     378      gsprintf(STDERR, "ReadTextFile::get_language_encoding {ReadTextFile.could_not_open_for_reading} ($!)\n", $filename);
     379      # this is a pretty bad error, but try to continue anyway
     380      return ($self->{'default_language'}, $self->{'input_encoding'});
    377381    }
    378382    my $text;
    379     sysread(FILE, $text, &util::file_size($filename));
     383    sysread($fh, $text, &FileUtils::fileSize($filename));
    380384    #undef $/;
    381385    #my $text = <FILE>;
    382386    #$/ = "\n";
    383     close FILE;
     387    close $fh;
    384388
    385389    # check if first few bytes have a Byte Order Marker
Note: See TracChangeset for help on using the changeset viewer.