Author: gnodet
Date: Sat May 19 19:06:46 2012
New Revision: 1340544
URL: http://svn.apache.org/viewvc?rev=1340544&view=rev
Log:
[SSHD-132] NativeSshFile does not close RandomAccessFile on IOException
Modified:
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/filesystem/NativeSshFile.java
Modified:
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/filesystem/NativeSshFile.java
URL:
http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/filesystem/NativeSshFile.java?rev=1340544&r1=1340543&r2=1340544&view=diff
==============================================================================
---
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/filesystem/NativeSshFile.java
(original)
+++
mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/filesystem/NativeSshFile.java
Sat May 19 19:06:46 2012
@@ -19,10 +19,6 @@
package org.apache.sshd.server.filesystem;
-import org.apache.sshd.server.SshFile;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -37,6 +33,10 @@ import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
+import org.apache.sshd.server.SshFile;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* <strong>Internal class, do not use directly.</strong>
*
@@ -284,8 +284,11 @@ public class NativeSshFile implements Ss
*/
public void truncate() throws IOException{
RandomAccessFile tempFile = new RandomAccessFile(file, "rw");
- tempFile.setLength(0);
- tempFile.close();
+ try {
+ tempFile.setLength(0);
+ } finally {
+ tempFile.close();
+ }
}
/**
@@ -370,19 +373,24 @@ public class NativeSshFile implements Ss
throw new IOException("No write permission : " + file.getName());
}
- // create output stream
+ // move to the appropriate offset and create output stream
final RandomAccessFile raf = new RandomAccessFile(file, "rw");
- raf.setLength(offset);
- raf.seek(offset);
+ try {
+ raf.setLength(offset);
+ raf.seek(offset);
- // The IBM jre needs to have both the stream and the random access file
- // objects closed to actually close the file
- return new FileOutputStream(raf.getFD()) {
- public void close() throws IOException {
- super.close();
- raf.close();
- }
- };
+ // The IBM jre needs to have both the stream and the random access
file
+ // objects closed to actually close the file
+ return new FileOutputStream(raf.getFD()) {
+ public void close() throws IOException {
+ super.close();
+ raf.close();
+ }
+ };
+ } catch (IOException e) {
+ raf.close();
+ throw e;
+ }
}
/**
@@ -397,16 +405,21 @@ public class NativeSshFile implements Ss
// move to the appropriate offset and create input stream
final RandomAccessFile raf = new RandomAccessFile(file, "r");
- raf.seek(offset);
+ try {
+ raf.seek(offset);
- // The IBM jre needs to have both the stream and the random access file
- // objects closed to actually close the file
- return new FileInputStream(raf.getFD()) {
- public void close() throws IOException {
- super.close();
- raf.close();
- }
- };
+ // The IBM jre needs to have both the stream and the random access
file
+ // objects closed to actually close the file
+ return new FileInputStream(raf.getFD()) {
+ public void close() throws IOException {
+ super.close();
+ raf.close();
+ }
+ };
+ } catch (IOException e) {
+ raf.close();
+ throw e;
+ }
}
public void handleClose() {