Author: markt
Date: Thu Jan 23 11:46:30 2014
New Revision: 1560646
URL: http://svn.apache.org/r1560646
Log:
Use try with resoucres
Modified:
tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
Modified: tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java?rev=1560646&r1=1560645&r2=1560646&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java Thu Jan
23 11:46:30 2014
@@ -647,10 +647,8 @@ public class DeltaManager extends Cluste
protected void deserializeSessions(byte[] data) throws
ClassNotFoundException,IOException {
// Open an input stream to the specified pathname, if any
- ObjectInputStream ois = null;
// Load the previously unloaded active sessions
- try {
- ois = getReplicationStream(data);
+ try (ObjectInputStream ois = getReplicationStream(data)) {
Integer count = (Integer) ois.readObject();
int n = count.intValue();
for (int i = 0; i < n; i++) {
@@ -691,14 +689,6 @@ public class DeltaManager extends Cluste
} catch (IOException e) {
log.error(sm.getString("deltaManager.loading.ioe", e), e);
throw e;
- } finally {
- // Close the input stream
- try {
- if (ois != null) ois.close();
- } catch (IOException f) {
- // ignored
- }
- ois = null;
}
}
@@ -714,12 +704,8 @@ public class DeltaManager extends Cluste
protected byte[] serializeSessions(Session[] currentSessions) throws
IOException {
// Open an output stream to the specified pathname, if any
- ByteArrayOutputStream fos = null;
- ObjectOutputStream oos = null;
-
- try {
- fos = new ByteArrayOutputStream();
- oos = new ObjectOutputStream(new BufferedOutputStream(fos));
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
+ try (ObjectOutputStream oos = new ObjectOutputStream(new
BufferedOutputStream(fos))) {
oos.writeObject(Integer.valueOf(currentSessions.length));
for(int i=0 ; i < currentSessions.length;i++) {
((DeltaSession)currentSessions[i]).writeObjectData(oos);
@@ -729,16 +715,8 @@ public class DeltaManager extends Cluste
} catch (IOException e) {
log.error(sm.getString("deltaManager.unloading.ioe", e), e);
throw e;
- } finally {
- if (oos != null) {
- try {
- oos.close();
- } catch (IOException f) {
- // Ignore
- }
- oos = null;
- }
}
+
// send object data as byte[]
return fos.toByteArray();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]