All pastes #238578 Raw Edit

Mine

public java v1 · immutable
·published 2006-11-05 01:17 UTC
rendered paste body
/* * Copyright (c) 2006, Serge Baranov. All Rights Reserved. */import java.io.UnsupportedEncodingException;import java.nio.charset.CharacterCodingException;public class TestRecode {  private static final String RUS_CAPITAL_I = "\u0418";  private static final String RUS_CAPITAL_II = "\u0419";  public static String encodeString(String text, String tocharset, String ourcharset) throws UnsupportedEncodingException, CharacterCodingException {    byte[] bytes = text.getBytes(tocharset);    return new String(bytes, ourcharset);  }  public static void main(String[] args) throws CharacterCodingException, UnsupportedEncodingException {    testString(RUS_CAPITAL_I);    testString(RUS_CAPITAL_II);  }  private static void testString(String source) throws UnsupportedEncodingException, CharacterCodingException {    String encoded = encodeString(source, "UTF-8", "windows-1251");    String decoded = encodeString(encoded, "windows-1251", "UTF-8");    System.out.print("TESTING '" + source + "': ");    if(decoded.equalsIgnoreCase(source)) {      System.out.println("OK");    } else {      System.out.println("FAILED");    }  }}