You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2018/11/02 23:59:34 UTC
[jspwiki] 05/17: use try with resources
This is an automated email from the ASF dual-hosted git repository.
juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 0964e8752a4f8cda4fd16fb0b9040b3a12ac5ba1
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Nov 2 21:56:49 2018 +0100
use try with resources
---
.../java/org/apache/wiki/ReferenceManager.java | 32 ++++------------------
1 file changed, 6 insertions(+), 26 deletions(-)
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ReferenceManager.java b/jspwiki-main/src/main/java/org/apache/wiki/ReferenceManager.java
index 12be34e..f12b698 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ReferenceManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ReferenceManager.java
@@ -321,18 +321,14 @@ public class ReferenceManager
throws IOException,
ClassNotFoundException
{
- ObjectInputStream in = null;
long saved = 0L;
- try
+ File f = new File( m_engine.getWorkDir(), SERIALIZATION_FILE );
+ try( ObjectInputStream in = new ObjectInputStream( new BufferedInputStream(new FileInputStream(f)) ) )
{
StopWatch sw = new StopWatch();
sw.start();
- File f = new File( m_engine.getWorkDir(), SERIALIZATION_FILE );
-
- in = new ObjectInputStream( new BufferedInputStream(new FileInputStream(f)) );
-
long ver = in.readLong();
if( ver != serialVersionUID )
@@ -352,10 +348,6 @@ public class ReferenceManager
sw.stop();
log.debug("Read serialized data successfully in "+sw);
}
- finally
- {
- if( in != null ) in.close();
- }
return saved;
}
@@ -365,17 +357,11 @@ public class ReferenceManager
*/
private synchronized void serializeToDisk()
{
- ObjectOutputStream out = null;
-
- try
- {
+ File f = new File( m_engine.getWorkDir(), SERIALIZATION_FILE );
+ try( ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream( new FileOutputStream( f ) ) ) ) {
StopWatch sw = new StopWatch();
sw.start();
- File f = new File( m_engine.getWorkDir(), SERIALIZATION_FILE );
-
- out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream(f)) );
-
out.writeLong( serialVersionUID );
out.writeLong( System.currentTimeMillis() ); // Timestamp
out.writeObject( m_refersTo );
@@ -387,15 +373,9 @@ public class ReferenceManager
log.debug("serialization done - took "+sw);
}
- catch( IOException e )
+ catch( IOException ioe )
{
- log.error("Unable to serialize!");
-
- try
- {
- if( out != null ) out.close();
- }
- catch( IOException ex ) {}
+ log.error("Unable to serialize!", ioe);
}
}