diff src/org/tmatesoft/hg/internal/EncodingHelper.java @ 418:528b6780a8bd

A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 22 Mar 2012 21:02:20 +0100
parents ee8264d80747
children 909306e412e2
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/EncodingHelper.java	Thu Mar 22 20:14:06 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/EncodingHelper.java	Thu Mar 22 21:02:20 2012 +0100
@@ -48,16 +48,13 @@
 		encoder = fsEncoding.newEncoder();
 	}
 
+	/**
+	 * Translate file names from manifest to amazing Unicode string 
+	 */
 	public String fromManifest(byte[] data, int start, int length) {
-		try {
-			return decoder.decode(ByteBuffer.wrap(data, start, length)).toString();
-		} catch (CharacterCodingException ex) {
-			sessionContext.getLog().error(getClass(), ex, String.format("Use of charset %s failed, resort to system default", charset().name()));
-			// resort to system-default
-			return new String(data, start, length);
-		}
+		return decodeWithSystemDefaultFallback(data, start, length);
 	}
-
+	
 	/**
 	 * @return byte representation of the string directly comparable to bytes in manifest
 	 */
@@ -80,11 +77,24 @@
 		}
 	}
 
-	public String fromDirstate(byte[] data, int start, int length) throws CharacterCodingException { // FIXME perhaps, log is enough, and charset() may be private?
-		return decoder.decode(ByteBuffer.wrap(data, start, length)).toString();
+	/**
+	 * Translate file names from dirstate to amazing Unicode string 
+	 */
+	public String fromDirstate(byte[] data, int start, int length) {
+		return decodeWithSystemDefaultFallback(data, start, length);
 	}
 
-	public Charset charset() {
+	private String decodeWithSystemDefaultFallback(byte[] data, int start, int length) {
+		try {
+			return decoder.decode(ByteBuffer.wrap(data, start, length)).toString();
+		} catch (CharacterCodingException ex) {
+			sessionContext.getLog().error(getClass(), ex, String.format("Use of charset %s failed, resort to system default", charset().name()));
+			// resort to system-default
+			return new String(data, start, length);
+		}
+	}
+
+	private Charset charset() {
 		return encoder.charset();
 	}