當前位置: 首頁>>代碼示例>>Java>>正文


Java Charset.defaultCharset方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:30,代碼來源:EncryptedMapDecorator.java

示例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();
    }
}
 
開發者ID:avaire,項目名稱:avaire,代碼行數:31,代碼來源:FileConfiguration.java

示例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();

}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:15,代碼來源:AbstractEncodedAppender.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:17,代碼來源:RuntimeExec.java

示例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);
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:34,代碼來源:AccessLogValve.java

示例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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:9,代碼來源:XMLUtils.java

示例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);
}
 
開發者ID:miyagilabs,項目名稱:Blindfold,代碼行數:36,代碼來源:TreeNodeTest.java

示例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();
  }
}
 
開發者ID:XDean,項目名稱:CSS-Editor-FX,代碼行數:8,代碼來源:Options.java

示例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);
}
 
開發者ID:miyagilabs,項目名稱:Blindfold,代碼行數:42,代碼來源:TreeTest.java

示例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);
        }
    }
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:13,代碼來源:DefaultEnApp.java

示例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);
    }
}
 
開發者ID:awslabs,項目名稱:emr-workload-profiler,代碼行數:9,代碼來源:Config.java

示例12: PrefixedStringCodecFactory

import java.nio.charset.Charset; //導入方法依賴的package包/類
public PrefixedStringCodecFactory() {
    this(Charset.defaultCharset());
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:4,代碼來源:PrefixedStringCodecFactory.java

示例13: StringWriteChannelListener

import java.nio.charset.Charset; //導入方法依賴的package包/類
public StringWriteChannelListener( final String string) {
    this(string, Charset.defaultCharset());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:4,代碼來源:StringWriteChannelListener.java

示例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));
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:6,代碼來源:Group.java

示例15: toCharset

import java.nio.charset.Charset; //導入方法依賴的package包/類
public static Charset toCharset(String charset) {
    return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
}
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:4,代碼來源:Charsets.java


注:本文中的java.nio.charset.Charset.defaultCharset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。