本文整理匯總了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);
}