Skip to content
Permalink
Browse files

[JENKINS-15382] Forgot to close the file

(cherry picked from commit 43ecda6)
  • Loading branch information...
kohsuke authored and olivergondza committed Jul 2, 2013
1 parent a3512b9 commit fca0ea8aa87ab18a1b398ce7bb8ba20bb8bde186
Showing with 13 additions and 9 deletions.
  1. +13 −9 core/src/main/java/hudson/util/TextFile.java
@@ -144,18 +144,22 @@ public void write(String text) throws IOException {
public @Nonnull String fastTail(int numChars, Charset cs) throws IOException {
RandomAccessFile raf = new RandomAccessFile(file,"r");

long len = raf.length();
// err on the safe side and assume each char occupies 4 bytes
// additional 1024 byte margin is to bring us back in sync in case we started reading from non-char boundary.
long pos = Math.max(0, len - (numChars*4+1024));
raf.seek(pos);
try {
long len = raf.length();
// err on the safe side and assume each char occupies 4 bytes
// additional 1024 byte margin is to bring us back in sync in case we started reading from non-char boundary.
long pos = Math.max(0, len - (numChars*4+1024));
raf.seek(pos);

byte[] tail = new byte[(int) (len-pos)];
raf.readFully(tail);
byte[] tail = new byte[(int) (len-pos)];
raf.readFully(tail);

String tails = new String(tail,cs);
String tails = new String(tail,cs);

return new String(tails.substring(Math.max(0,tails.length()-numChars))); // trim the baggage of substring by allocating a new String
return new String(tails.substring(Math.max(0,tails.length()-numChars))); // trim the baggage of substring by allocating a new String
} finally {
raf.close();
}
}

/**

0 comments on commit fca0ea8

Please sign in to comment.
You can’t perform that action at this time.