ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1815113 - /ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java
Date Mon, 13 Nov 2017 15:42:28 GMT
Author: seanfinan
Date: Mon Nov 13 15:42:28 2017
New Revision: 1815113

URL: http://svn.apache.org/viewvc?rev=1815113&view=rev
Log:
Fix for possible bug involving too many open files.  Apparently Files.lines() doesn't auto-close
at eos.

Modified:
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java?rev=1815113&r1=1815112&r2=1815113&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java (original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cr/FileTreeReader.java Mon
Nov 13 15:42:28 2017
@@ -24,6 +24,7 @@ import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 
 /**
@@ -301,7 +302,7 @@ final public class FileTreeReader extend
    private String readFile( final File file ) throws IOException {
       try {
          return readByPath( file );
-      } catch ( UncheckedIOException uE ) {
+      } catch ( IOException ioE ) {
          // This is a pretty bad way to handle a MalformedInputException, but that can be
thrown by the collector
          // in the stream, and java streams and exceptions do not go well together
          LOGGER.warn( "Bad characters in " + file.getPath() );
@@ -319,9 +320,13 @@ final public class FileTreeReader extend
    private String readByPath( final File file ) throws IOException {
       if ( _encoding != null && !_encoding.isEmpty() ) {
          final Charset charset = Charset.forName( _encoding );
-         return Files.lines( file.toPath(), charset ).collect( Collectors.joining( "\n" )
);
+         try ( Stream<String> stream = Files.lines( file.toPath(), charset ) ) {
+            return stream.collect( Collectors.joining( "\n" ) );
+         }
       } else {
-         return Files.lines( file.toPath() ).collect( Collectors.joining( "\n" ) );
+         try ( Stream<String> stream = Files.lines( file.toPath() ) ) {
+            return stream.collect( Collectors.joining( "\n" ) );
+         }
       }
    }
 



Mime
View raw message