You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/12/30 19:06:25 UTC

[incubator-nlpcraft] branch NLPCRAFT-472 updated: Fix 'ignoring'.

This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-472
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-472 by this push:
     new 2b56686  Fix 'ignoring'.
2b56686 is described below

commit 2b56686e7554c8443ba19cb1ff95a9960393ea17
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Thu Dec 30 11:06:19 2021 -0800

    Fix 'ignoring'.
---
 .../apache/nlpcraft/internal/util/NCUtils.scala    | 46 ++++++++--------------
 .../opennlp/impl/NCOpenNlpEntityParserImpl.scala   |  1 -
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
index bad8159..dcf24cb 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
@@ -35,7 +35,6 @@ import scala.concurrent.*
 import scala.io.Source
 import scala.sys.SystemProperties
 import scala.util.Using
-import scala.util.control.Exception.ignoring
 import scala.io.BufferedSource
 
 /**
@@ -609,10 +608,8 @@ object NCUtils extends LazyLogging:
     def stopThread(t: Thread): Unit =
         if t != null then
             t.interrupt()
-            try
-                t.join()
-            catch
-                case _: InterruptedException => logger.trace("Thread joining was interrupted (ignoring).")
+            try t.join()
+            catch case _: InterruptedException => logger.trace("Thread joining was interrupted (ignoring).")
 
     /**
       * Interrupts thread.
@@ -659,9 +656,8 @@ object NCUtils extends LazyLogging:
       */
     def close(sock: Socket): Unit =
         if sock != null then
-            ignoring(classOf[IOException]) {
-                sock.close()
-            }
+            try sock.close()
+            catch case _: Exception => ()
 
     /**
       * Safely and silently closes the server socket.
@@ -670,9 +666,8 @@ object NCUtils extends LazyLogging:
       */
     def close(sock: ServerSocket): Unit =
         if sock != null then
-            ignoring(classOf[IOException]) {
-                sock.close()
-            }
+            try sock.close()
+            catch case _: Exception => ()
 
     /**
       *
@@ -680,9 +675,8 @@ object NCUtils extends LazyLogging:
       */
     def close(in: InputStream): Unit =
         if in != null then
-            ignoring(classOf[IOException]) {
-                in.close()
-            }
+            try in.close()
+            catch case _: Exception => ()
 
     /**
       *
@@ -690,9 +684,8 @@ object NCUtils extends LazyLogging:
       */
     def close(out: OutputStream): Unit =
         if out != null then
-            ignoring(classOf[IOException]) {
-                out.close()
-            }
+            try out.close()
+            catch case _: Exception => ()
 
     /**
       * Closes auto-closeable ignoring any exceptions.
@@ -701,9 +694,8 @@ object NCUtils extends LazyLogging:
       */
     def close(a: AutoCloseable): Unit =
         if a != null then
-            ignoring(classOf[Exception]) {
-                a.close()
-            }
+            try a.close()
+            catch case _: Exception => ()
 
     /**
       *
@@ -812,9 +804,7 @@ object NCUtils extends LazyLogging:
     def readFileBytes(f: File, log: Logger = logger): Array[Byte] =
         try
             val arr = new Array[Byte](f.length().toInt)
-
             Using.resource(new FileInputStream(f))(_.read(arr))
-
             getAndLog(arr, f, log)
         catch
             case e: IOException => throw new NCException(s"Error reading file: $f", e)
@@ -870,10 +860,8 @@ object NCUtils extends LazyLogging:
       */
     def readResource(res: String, enc: String = "UTF-8", log: Logger = logger): List[String] =
         val list =
-            try
-                Using.resource(Source.fromInputStream(getStream(res), enc))(_.getLines().toSeq).toList
-            catch
-                case e: IOException => throw new NCException(s"Failed to read stream: $res", e)
+            try Using.resource(Source.fromInputStream(getStream(res), enc))(_.getLines().toSeq).toList
+            catch case e: IOException => throw new NCException(s"Failed to read stream: $res", e)
     
         log.trace(s"Loaded resource: $res")
 
@@ -897,10 +885,8 @@ object NCUtils extends LazyLogging:
       */
     def readTextGzipResource(res: String, enc: String, log: Logger = logger): List[String] =
         val list =
-            try
-                Using.resource(Source.fromInputStream(new GZIPInputStream(getStream(res)), enc))(readLcTrimFilter)
-            catch
-                case e: IOException => throw new NCException(s"Failed to read stream: $res", e)
+            try Using.resource(Source.fromInputStream(new GZIPInputStream(getStream(res)), enc))(readLcTrimFilter)
+            catch case e: IOException => throw new NCException(s"Failed to read stream: $res", e)
 
         log.trace(s"Loaded resource: $res")
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/opennlp/impl/NCOpenNlpEntityParserImpl.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/opennlp/impl/NCOpenNlpEntityParserImpl.scala
index c6a97a3..f35b46e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/opennlp/impl/NCOpenNlpEntityParserImpl.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/opennlp/impl/NCOpenNlpEntityParserImpl.scala
@@ -30,7 +30,6 @@ import scala.concurrent.ExecutionContext
 import scala.jdk.CollectionConverters.*
 import scala.language.postfixOps
 import scala.util.Using
-import scala.util.control.Exception.catching
 
 object NCOpenNlpEntityParserImpl:
     def apply(res: String): NCOpenNlpEntityParserImpl = new NCOpenNlpEntityParserImpl(NCUtils.getStream(res), res)