comparison src/org/tmatesoft/hg/internal/EncodingHelper.java @ 456:909306e412e2

Refactor LogFacility and SessionContext, better API for both
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 18 Jun 2012 16:54:00 +0200
parents 528b6780a8bd
children 0be5be8d57e9
comparison
equal deleted inserted replaced
454:36fd1fd06492 456:909306e412e2
13 * For information on how to redistribute this software under 13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License 14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.internal; 17 package org.tmatesoft.hg.internal;
18
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Error;
18 20
19 import java.nio.ByteBuffer; 21 import java.nio.ByteBuffer;
20 import java.nio.CharBuffer; 22 import java.nio.CharBuffer;
21 import java.nio.charset.CharacterCodingException; 23 import java.nio.charset.CharacterCodingException;
22 import java.nio.charset.Charset; 24 import java.nio.charset.Charset;
69 // } 71 // }
70 byte[] rv = new byte[bb.remaining()]; 72 byte[] rv = new byte[bb.remaining()];
71 bb.get(rv, 0, rv.length); 73 bb.get(rv, 0, rv.length);
72 return rv; 74 return rv;
73 } catch (CharacterCodingException ex) { 75 } catch (CharacterCodingException ex) {
74 sessionContext.getLog().error(getClass(), ex, String.format("Use of charset %s failed, resort to system default", charset().name())); 76 sessionContext.getLog().dump(getClass(), Error, ex, String.format("Use of charset %s failed, resort to system default", charset().name()));
75 // resort to system-default 77 // resort to system-default
76 return s.getBytes(); 78 return s.getBytes();
77 } 79 }
78 } 80 }
79 81
86 88
87 private String decodeWithSystemDefaultFallback(byte[] data, int start, int length) { 89 private String decodeWithSystemDefaultFallback(byte[] data, int start, int length) {
88 try { 90 try {
89 return decoder.decode(ByteBuffer.wrap(data, start, length)).toString(); 91 return decoder.decode(ByteBuffer.wrap(data, start, length)).toString();
90 } catch (CharacterCodingException ex) { 92 } catch (CharacterCodingException ex) {
91 sessionContext.getLog().error(getClass(), ex, String.format("Use of charset %s failed, resort to system default", charset().name())); 93 sessionContext.getLog().dump(getClass(), Error, ex, String.format("Use of charset %s failed, resort to system default", charset().name()));
92 // resort to system-default 94 // resort to system-default
93 return new String(data, start, length); 95 return new String(data, start, length);
94 } 96 }
95 } 97 }
96 98