diff src/org/tmatesoft/hg/internal/EncodingHelper.java @ 320:678e326fd27c

Issue 15: Exception accessing oddly named file from history
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 30 Sep 2011 06:22:11 +0200
parents
children ac38e75c9e8e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/tmatesoft/hg/internal/EncodingHelper.java	Fri Sep 30 06:22:11 2011 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011 TMate Software Ltd
+ *  
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * For information on how to redistribute this software under
+ * the terms of a license other than GNU General Public License
+ * contact TMate Software at support@hg4j.com
+ */
+package org.tmatesoft.hg.internal;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+
+import org.tmatesoft.hg.core.HgBadStateException;
+
+/**
+ * Keep all encoding-related issues in the single place
+ * @author Artem Tikhomirov
+ * @author TMate Software Ltd.
+ */
+public class EncodingHelper {
+	// XXX perhaps, shall not be full of statics, but rather an instance coming from e.g. HgRepository?
+
+	public static String fromManifest(byte[] data, int start, int length) {
+		try {
+			return new String(data, start, length, "ISO-8859-1");
+		} catch (UnsupportedEncodingException ex) {
+			// can't happen
+			throw new HgBadStateException(ex);
+		}
+	}
+}