当前位置: 首页>>代码示例>>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;未经允许,请勿转载。