下面列出了java.nio.charset.Charset#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void loadCompilerOptions() {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
mCompileOptions = new CompileOptions();
String sourceCompatibility = pref.getString(context.getString(R.string.key_pref_source_compatibility), null);
if (sourceCompatibility == null || sourceCompatibility.isEmpty()) {
sourceCompatibility = JavaVersion.VERSION_1_7.toString();
}
mCompileOptions.setSourceCompatibility(sourceCompatibility);
String targetCompatibility = pref.getString(context.getString(R.string.key_pref_target_compatibility), null);
if (targetCompatibility == null || targetCompatibility.isEmpty()) {
targetCompatibility = JavaVersion.VERSION_1_7.toString();
}
mCompileOptions.setTargetCompatibility(targetCompatibility);
String encoding = pref.getString(context.getString(R.string.key_pref_source_encoding), null);
if (encoding == null || encoding.isEmpty()) {
encoding = Charset.forName("UTF-8").toString();
} else {
try {
Charset charset = Charset.forName(encoding);
encoding = charset.toString();
} catch (Exception e) {
encoding = Charset.forName("UTF-8").toString();
}
}
mCompileOptions.setEncoding(encoding);
}
public static String convertCharset(Charset charset) {
String s = charset.toString();
int i = s.indexOf("[");
if (i == -1)
return s;
return s.substring(i + 1, s.length() - 1);
}
public static String convertCharset(Charset charset) {
String s = charset.toString();
int i = s.indexOf("[");
if (i == -1) {
return s;
}
return s.substring(i + 1, s.length() - 1);
}
public static String convertCharset(Charset charset) {
String s = charset.toString();
int i = s.indexOf("[");
if (i == -1) {
return s;
}
return s.substring(i + 1, s.length() - 1);
}
public static String readFileToString(String path, Charset charset) {
try (UnicodeReader reader = new UnicodeReader(new FileInputStream(new File(path)), charset.toString())) {
return IOUtils.toString(reader);
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
private String getResponseBodyAsString(ClientHttpResponse response) {
try {
Charset charset = getCharset(response);
return new String(getResponseBody(response), charset != null ? charset.toString() : DEFAULT_CHARSET);
} catch (UnsupportedEncodingException ex) {
throw new InternalException(RestClientResponseErrorHandler.class, "E-SPRINGMVC-REST-CLIENT-HANDLER#0001");
}
}
public FromFileProperty(File file, Class type, Charset charset) {
this.file = file;
this.type = type;
this.charset = charset.toString();
}