diff src/org/tmatesoft/hg/internal/ChangelogEntryBuilder.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 7c0d2ce340b8
children fba85bc1dfb8
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/ChangelogEntryBuilder.java	Sat May 18 22:23:57 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/ChangelogEntryBuilder.java	Mon May 20 16:56:40 2013 +0200
@@ -17,6 +17,7 @@
 package org.tmatesoft.hg.internal;
 
 import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -30,6 +31,7 @@
 import org.tmatesoft.hg.core.HgIOException;
 import org.tmatesoft.hg.core.Nodeid;
 import org.tmatesoft.hg.internal.DataSerializer.DataSource;
+import org.tmatesoft.hg.repo.HgInvalidStateException;
 import org.tmatesoft.hg.util.Path;
 
 /**
@@ -114,32 +116,36 @@
 	}
 
 	public byte[] build() {
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		final int LF = '\n';
-		CharSequence extras = buildExtras();
-		CharSequence files = buildFiles();
-		byte[] manifestRevision = manifestRev.toString().getBytes();
-		byte[] username = user().getBytes(EncodingHelper.getUTF8());
-		out.write(manifestRevision, 0, manifestRevision.length);
-		out.write(LF);
-		out.write(username, 0, username.length);
-		out.write(LF);
-		final long csetDate = csetTime();
-		byte[] date = String.format("%d %d", csetDate, csetTimezone(csetDate)).getBytes();
-		out.write(date, 0, date.length);
-		if (extras.length() > 0) {
-			out.write(' ');
-			byte[] b = extras.toString().getBytes();
+		try {
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			final int LF = '\n';
+			CharSequence extras = buildExtras();
+			CharSequence files = buildFiles();
+			byte[] manifestRevision = manifestRev.toString().getBytes();
+			byte[] username = user().getBytes(EncodingHelper.getUTF8().name()); // XXX Java 1.5
+			out.write(manifestRevision, 0, manifestRevision.length);
+			out.write(LF);
+			out.write(username, 0, username.length);
+			out.write(LF);
+			final long csetDate = csetTime();
+			byte[] date = String.format("%d %d", csetDate, csetTimezone(csetDate)).getBytes();
+			out.write(date, 0, date.length);
+			if (extras.length() > 0) {
+				out.write(' ');
+				byte[] b = extras.toString().getBytes();
+				out.write(b, 0, b.length);
+			}
+			out.write(LF);
+			byte[] b = files.toString().getBytes();
 			out.write(b, 0, b.length);
+			out.write(LF);
+			out.write(LF);
+			byte[] cmt = comment.toString().getBytes(EncodingHelper.getUTF8().name()); // XXX Java 1.5
+			out.write(cmt, 0, cmt.length);
+			return out.toByteArray();
+		} catch (UnsupportedEncodingException ex) {
+			throw new HgInvalidStateException(ex.getMessage()); // Can't happen, UTF8 is always there
 		}
-		out.write(LF);
-		byte[] b = files.toString().getBytes();
-		out.write(b, 0, b.length);
-		out.write(LF);
-		out.write(LF);
-		byte[] cmt = comment.toString().getBytes(EncodingHelper.getUTF8());
-		out.write(cmt, 0, cmt.length);
-		return out.toByteArray();
 	}
 
 	private CharSequence buildExtras() {