From cfa3f365d6e526a10aa80004c7291cf1c89fbb0e Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 9 Nov 2010 19:12:24 -0800 Subject: [PATCH] Simplify LockFile write(ObjectId) case The ObjectId (for a ref) can be easily reformatted into a temporary byte[] and then passed off to write(byte[]), removing the duplicated code that existed in both write methods. Change-Id: I09740658e070d5f22682333a2e0d325fd1c4a6cb Signed-off-by: Shawn O. Pearce --- .../eclipse/jgit/storage/file/LockFile.java | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java index e8bc3e2cf..1a4952ad0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java @@ -44,7 +44,6 @@ package org.eclipse.jgit.storage.file; -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -229,26 +228,10 @@ public class LockFile { * before throwing the underlying exception to the caller. */ public void write(final ObjectId id) throws IOException { - requireLock(); - try { - final BufferedOutputStream b; - b = new BufferedOutputStream(os, Constants.OBJECT_ID_STRING_LENGTH + 1); - id.copyTo(b); - b.write('\n'); - b.flush(); - fLck.release(); - b.close(); - os = null; - } catch (IOException ioe) { - unlock(); - throw ioe; - } catch (RuntimeException ioe) { - unlock(); - throw ioe; - } catch (Error ioe) { - unlock(); - throw ioe; - } + byte[] buf = new byte[Constants.OBJECT_ID_STRING_LENGTH + 1]; + id.copyTo(buf, 0); + buf[Constants.OBJECT_ID_STRING_LENGTH] = '\n'; + write(buf); } /**