本文整理汇总了Java中java.nio.charset.Charset.defaultCharset方法的典型用法代码示例。如果您正苦于以下问题:Java Charset.defaultCharset方法的具体用法?Java Charset.defaultCharset怎么用?Java Charset.defaultCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.Charset
的用法示例。
在下文中一共展示了Charset.defaultCharset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Decrypt the value.
*
* @param value the value
* @param hashedKey the hashed key
* @return the string
*/
protected String decrypt(final String value, final String hashedKey) {
if (value == null) {
return null;
}
try {
final Cipher cipher = getCipherObject();
final byte[] ivCiphertext = CompressionUtils.decodeBase64ToByteArray(value);
final int ivSize = byte2int(Arrays.copyOfRange(ivCiphertext, 0, INTEGER_LEN));
final byte[] ivValue = Arrays.copyOfRange(ivCiphertext, INTEGER_LEN, (INTEGER_LEN + ivSize));
final byte[] ciphertext = Arrays.copyOfRange(ivCiphertext, INTEGER_LEN + ivSize, ivCiphertext.length);
final IvParameterSpec ivSpec = new IvParameterSpec(ivValue);
cipher.init(Cipher.DECRYPT_MODE, this.key, ivSpec);
final byte[] plaintext = cipher.doFinal(ciphertext);
return new String(plaintext, Charset.defaultCharset());
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例2: save
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Saves this {@link FileConfiguration} to the specified location.
* <p>
* If the file does not exist, it will be created. If already exists, it
* will be overwritten. If it cannot be overwritten or created, an
* exception will be thrown.
* <p>
* This method will save using the system default encoding, or possibly
* using UTF8.
*
* @param file File to save to.
* @throws IOException Thrown when the given file cannot be written to for
* any reason.
* @throws IllegalArgumentException Thrown when file is null.
*/
public void save(File file) throws IOException {
Validate.notNull(file, "File cannot be null");
Files.createParentDirs(file);
String data = saveToString();
Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? Charsets.UTF_8 : Charset.defaultCharset());
try {
writer.write(data);
} finally {
writer.close();
}
}
示例3: getCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Charset取得 (取れる範囲で)
*
* @return Charset
*/
protected Charset getCharset() {
Charset charset = null;
if (this.encoder instanceof LayoutWrappingEncoder) {
charset = ((LayoutWrappingEncoder<?>) this.encoder).getCharset();
}
return charset != null ? charset : Charset.defaultCharset();
}
示例4: RuntimeExec
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Default constructor. Initialize this instance by setting individual properties.
*/
public RuntimeExec()
{
this.charset = Charset.defaultCharset();
this.waitForCompletion = true;
defaultProperties = Collections.emptyMap();
processProperties = null;
processDirectory = null;
// set default error codes
this.errCodes = new HashSet<Integer>(2);
errCodes.add(1);
errCodes.add(2);
}
示例5: open
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Open the new log file for the date specified by <code>dateStamp</code>.
*/
protected synchronized void open() {
// Open the current log file
// If no rotate - no need for dateStamp in fileName
File pathname = getLogFile(rotatable && !renameOnRotate);
Charset charset = null;
if (encoding != null) {
try {
charset = B2CConverter.getCharset(encoding);
} catch (UnsupportedEncodingException ex) {
log.error(sm.getString(
"accessLogValve.unsupportedEncoding", encoding), ex);
}
}
if (charset == null) {
charset = Charset.defaultCharset();
}
try {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(pathname, true), charset), 128000),
false);
currentLogFile = pathname;
} catch (IOException e) {
writer = null;
currentLogFile = null;
log.error(sm.getString("accessLogValve.openFail", pathname), e);
}
}
示例6: getEncoding
import java.nio.charset.Charset; //导入方法依赖的package包/类
public static Charset getEncoding(byte[] bytes, Charset charset) {
try {
String encoding = new String(bytes, 0, Math.min(bytes.length, 128), "ASCII").replaceFirst("[\\d\\D]*encoding=\"(.*?)\"[\\d\\D]*", "$1");
charset = Charset.forName(encoding);
} catch (Exception e) { }
return charset == null ? Charset.defaultCharset() : charset;
}
示例7: testEquals
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Test of equals method, of class TreeNode.
*
* @throws java.io.IOException
*/
@Test
public void testEquals() throws IOException {
Object object = null;
TreeNode instance = new TreeNode(new ParserRuleContext());
boolean expResult = false;
boolean result = instance.equals(object);
assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult,
result);
object = new Object();
expResult = false;
result = instance.equals(object);
assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult,
result);
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(SAMPLE_CLASS_PATH).getFile());
byte[] encoded = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
String code = new String(encoded, Charset.defaultCharset());
Forest forest1 = TreeViewGenerator.generate(code);
Forest forest2 = TreeViewGenerator.generate(code);
expResult = true;
object = forest1.getTree(0).getRoot();
instance = forest2.getTree(0).getRoot();
result = instance.equals(object);
assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult,
result);
}
示例8: safeCharSet
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static Charset safeCharSet(String charsetName) {
if (Charset.isSupported(charsetName)) {
return Charset.forName(charsetName);
} else {
return Charset.defaultCharset();
}
}
示例9: testEquals
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Test of equals method, of class Tree.
*
* @throws java.io.IOException
*/
@Test
public void testEquals() throws IOException {
Object object = null;
Tree instance = new Tree(new TreeNode(new ParserRuleContext()));
boolean expResult = false;
boolean result = instance.equals(object);
assertEquals("equals method, of class Tree's expected result is wrong.", expResult, result);
object = new Object();
expResult = false;
result = instance.equals(object);
assertEquals("equals method, of class Tree's expected result is wrong.", expResult, result);
object = instance;
expResult = true;
result = instance.equals(object);
assertEquals("equals method, of class Tree's expected result is wrong.", expResult, result);
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(SAMPLE_CLASS_PATH).getFile());
byte[] encoded = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
String code = new String(encoded, Charset.defaultCharset());
Forest forest = TreeViewGenerator.generate(code);
Tree tree1 = forest.getTree(0);
Tree tree2 = forest.getTree(1);
result = tree1.equals(tree2);
expResult = false;
assertEquals("equals method, of class Tree's expected result is wrong.", expResult, result);
tree1 = TreeViewGenerator.generate(code).getTree(0);
tree2 = TreeViewGenerator.generate(code).getTree(0);
result = tree1.equals(tree2);
expResult = true;
assertEquals("equals method, of class Tree's expected result is wrong.", expResult, result);
}
示例10: DefaultEnApp
import java.nio.charset.Charset; //导入方法依赖的package包/类
public DefaultEnApp(){
try(InputStream is =Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/app.properties")) {
if(is!=null) {
try(InputStreamReader reader =new InputStreamReader(is, Charset.defaultCharset())) {
properties.load(reader);
}
}
} catch (Throwable e) {
logger.warn("read app info error!", e);
}
}
示例11: tryParseConfig
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static Config tryParseConfig(File configFile, Gson serializer) throws Exception {
try ( FileInputStream inputStream = new FileInputStream(configFile);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charset.defaultCharset());
JsonReader reader = new JsonReader(inputStreamReader)
) {
return serializer.fromJson(reader, Config.class);
}
}
示例12: PrefixedStringCodecFactory
import java.nio.charset.Charset; //导入方法依赖的package包/类
public PrefixedStringCodecFactory() {
this(Charset.defaultCharset());
}
示例13: StringWriteChannelListener
import java.nio.charset.Charset; //导入方法依赖的package包/类
public StringWriteChannelListener( final String string) {
this(string, Charset.defaultCharset());
}
示例14: Group
import java.nio.charset.Charset; //导入方法依赖的package包/类
private Group(File file) throws IOException {
this.path = file.getCanonicalFile().toPath();
String text = new String(Files.readAllBytes(this.path), Charset.defaultCharset());
init(new JSONObject(text));
}
示例15: toCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
public static Charset toCharset(String charset) {
return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
}