- Timestamp:
- 2013-05-21T14:46:55+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/parallel-building/trunk/src/perllib/plugins/ReadTextFile.pm
r26963 r27377 39 39 use ghtml; 40 40 use gsprintf 'gsprintf'; 41 use util; 42 use FileUtils; 41 43 42 44 use AutoExtractMetadata; … … 140 142 # this should look at the plugin option too... 141 143 $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)); 143 145 144 146 my $plugin_filename_encoding = $self->{'filename_encoding'}; … … 202 204 my ($filename, $encoding, $language, $textref) = @_; 203 205 204 if (!& util::file_canread($filename))206 if (!&FileUtils::canRead($filename)) 205 207 { 206 208 my $outhandle = $self->{'outhandle'}; … … 213 215 # use the util::file_* functions to provide some extra smarts to the open 214 216 # 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)) 216 219 { 217 220 gsprintf(STDERR, "ReadTextFile::read_file {ReadTextFile.could_not_open_for_reading} ($!)\n", $filename); … … 222 225 { 223 226 # fast file 'slurp' implementation 224 sysread( FILE, $$textref, &util::file_size($filename));227 sysread($fh, $$textref, &FileUtils::fileSize($filename)); 225 228 # the old slow way of reading in a file 226 229 #undef $/; … … 231 234 { 232 235 my $reader = new multiread(); 233 $reader->set_handle ( 'ReadTextFile::FILE');236 $reader->set_handle ($fh); 234 237 $reader->set_encoding ($encoding); 235 238 $reader->read_file ($textref); … … 243 246 $$textref = decode("utf8", $$textref); 244 247 245 close FILE;248 &FileUtils::closeFileHandle($filename, \$fh); 246 249 } 247 250 … … 368 371 my $best_language = ""; 369 372 my $best_encoding = ""; 370 371 373 372 374 # 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'}); 377 381 } 378 382 my $text; 379 sysread( FILE, $text, &util::file_size($filename));383 sysread($fh, $text, &FileUtils::fileSize($filename)); 380 384 #undef $/; 381 385 #my $text = <FILE>; 382 386 #$/ = "\n"; 383 close FILE;387 close $fh; 384 388 385 389 # check if first few bytes have a Byte Order Marker
Note:
See TracChangeset
for help on using the changeset viewer.