diff src/org/tmatesoft/hg/internal/RepoInitializer.java @ 622:4e6179bde4fc

Update to comply with Java 1.5 target
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 May 2013 16:56:40 +0200
parents ba36f66c32b4
children 4a0bab2c6da1
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RepoInitializer.java	Sat May 18 22:23:57 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/RepoInitializer.java	Mon May 20 16:56:40 2013 +0200
@@ -23,6 +23,7 @@
 import java.io.IOException;
 import java.nio.charset.Charset;
 
+import org.tmatesoft.hg.core.HgIOException;
 import org.tmatesoft.hg.core.SessionContext;
 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
 import org.tmatesoft.hg.util.PathRewrite;
@@ -59,22 +60,27 @@
 		return requiresFlags;
 	}
 
-	public void initEmptyRepository(File repoDir) throws IOException {
+	public void initEmptyRepository(File repoDir) throws HgIOException {
 		repoDir.mkdirs();
-		FileOutputStream requiresFile = new FileOutputStream(new File(repoDir, "requires"));
-		StringBuilder sb = new StringBuilder(40);
-		sb.append("revlogv1\n");
-		if ((requiresFlags & STORE) != 0) {
-			sb.append("store\n");
+		final File requiresFile = new File(repoDir, "requires");
+		try {
+			FileOutputStream requiresStream = new FileOutputStream(requiresFile);
+			StringBuilder sb = new StringBuilder(40);
+			sb.append("revlogv1\n");
+			if ((requiresFlags & STORE) != 0) {
+				sb.append("store\n");
+			}
+			if ((requiresFlags & FNCACHE) != 0) {
+				sb.append("fncache\n");
+			}
+			if ((requiresFlags & DOTENCODE) != 0) {
+				sb.append("dotencode\n");
+			}
+			requiresStream.write(sb.toString().getBytes());
+			requiresStream.close();
+		} catch (IOException ex) {
+			throw new HgIOException("Failed to initialize empty repo", ex, requiresFile);
 		}
-		if ((requiresFlags & FNCACHE) != 0) {
-			sb.append("fncache\n");
-		}
-		if ((requiresFlags & DOTENCODE) != 0) {
-			sb.append("dotencode\n");
-		}
-		requiresFile.write(sb.toString().getBytes());
-		requiresFile.close();
 		new File(repoDir, "store").mkdir(); // with that, hg verify says ok.
 	}