本文整理了Java中java.nio.charset.Charset.defaultCharset()
方法的一些代码示例,展示了Charset.defaultCharset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Charset.defaultCharset()
方法的具体详情如下:
包路径:java.nio.charset.Charset
类名称:Charset
方法名:defaultCharset
[英]Returns the system's default charset. This is determined during VM startup, and will not change thereafter. On Android, the default charset is UTF-8.
[中]返回系统的默认字符集。这是在VM启动期间确定的,此后不会更改。在Android上,默认字符集是UTF-8。
代码示例来源:origin: commons-io/commons-io
/**
* Returns a Charset for the named charset. If the name is null, return the default Charset.
*
* @param charset
* The name of the requested charset, may be null.
* @return a Charset for the named charset
* @throws java.nio.charset.UnsupportedCharsetException
* If the named charset is unavailable
*/
public static Charset toCharset(final String charset) {
return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
}
代码示例来源:origin: jenkinsci/jenkins
public String call() throws IOException {
return Charset.defaultCharset().name();
}
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public void write(D record) throws IOException {
if (null != record) {
String s = record.toString();
System.out.println(s);
++ _numRecordsWritten;
_numBytesWritten += s.getBytes(Charset.defaultCharset()).length;
}
}
代码示例来源:origin: stackoverflow.com
import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
// ...
Path filePath = new File("fileName").toPath();
Charset charset = Charset.defaultCharset();
List<String> stringList = Files.readAllLines(filePath, charset);
String[] stringArray = stringList.toArray(new String[]{});
代码示例来源:origin: commons-io/commons-io
@Test
public void testMultiByteBreak() throws Exception {
System.out.println("testMultiByteBreak() Default charset: "+Charset.defaultCharset().displayName());
final long delay = 50;
final File origin = new File(this.getClass().getResource("/test-file-utf8.bin").toURI());
final File file = new File(getTestDirectory(), "testMultiByteBreak.txt");
createFile(file, 0);
final TestTailerListener listener = new TestTailerListener();
代码示例来源:origin: sleekbyte/tailor
@Before
public void setUp() throws IOException {
inputFile = new File(TEST_INPUT_DIR);
expectedMessages = new ArrayList<>();
outContent = new ByteArrayOutputStream();
errContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent, false, Charset.defaultCharset().name()));
System.setErr(new PrintStream(errContent, false, Charset.defaultCharset().name()));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void sameEncoding_string_CharsetEncoder_constructor() throws Exception {
final CharsetEncoder enc = Charset.defaultCharset().newEncoder();
succesfulRun(new FileWriterWithEncoding(file2.getPath(), enc));
}
代码示例来源:origin: embulk/embulk
public static void main(String[] args) throws Exception {
System.out.println(Arrays.asList(args));
File thisFolder = new File(SelfrunTest.class.getResource("/org/embulk/cli/DummyMain.class").toURI()).getParentFile();
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(thisFolder, "args.txt")), Charset.defaultCharset()))) {
for (String arg : args) {
writer.write(arg);
writer.newLine();
}
}
}
}
代码示例来源:origin: sleekbyte/tailor
@Test
public void testTwoSourceInputFiles() throws IOException {
File inputFile1 = new File(TEST_DIR + "/UpperCamelCaseTest.swift");
File inputFile2 = new File(TEST_DIR + "/LowerCamelCaseTest.swift");
String[] command = {"--no-color",
inputFile1.getPath(),
inputFile2.getPath()
};
Tailor.main(command);
String[] msgs = outContent.toString(Charset.defaultCharset().name()).split(NEWLINE_REGEX);
String actualSummary = msgs[msgs.length - 1];
assertTrue(actualSummary.startsWith("Analyzed 2 files, skipped 0 files"));
}
代码示例来源:origin: apache/kylin
@Test
public void testScp() throws Exception {
if (isRemote == false)
return;
SSHClient ssh = new SSHClient(this.hostname, this.port, this.username, this.password);
File tmpFile = File.createTempFile("test_scp", "", new File("/tmp"));
tmpFile.deleteOnExit();
FileUtils.write(tmpFile, "test_scp", Charset.defaultCharset());
ssh.scpFileToRemote(tmpFile.getAbsolutePath(), "/tmp");
}
}
代码示例来源:origin: sleekbyte/tailor
@Test
public void testDisplaySummary() throws IOException {
final long files = 5;
final long skipped = 1;
final long errors = 7;
final long warnings = 4;
formatter.displaySummary(files, skipped, errors, warnings);
assertThat(outContent.toString(Charset.defaultCharset().name()), isEmptyString());
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testToCharset() {
Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null));
Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null));
Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset()));
Assert.assertEquals(Charset.forName("UTF-8"), Charsets.toCharset(Charset.forName("UTF-8")));
}
代码示例来源:origin: apache/incubator-druid
private ImmutableSortedMap<String, ImmutableSet<String>> readMap(final String mapPath)
{
String fileContent;
String actualPath = mapPath;
try {
if (Strings.isNullOrEmpty(mapPath)) {
URL resource = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json");
actualPath = resource.getFile();
LOGGER.info("using default whiteList map located at [%s]", actualPath);
fileContent = Resources.toString(resource, Charset.defaultCharset());
} else {
fileContent = Files.asCharSource(new File(mapPath), Charset.forName("UTF-8")).read();
}
return mapper.readerFor(new TypeReference<ImmutableSortedMap<String, ImmutableSet<String>>>()
{
}).readValue(fileContent);
}
catch (IOException e) {
throw new ISE(e, "Got an exception while parsing file [%s]", actualPath);
}
}
}
代码示例来源:origin: apache/ignite
/**
* Main method being triggered in step 3 of the Workaround.
* <p>
* Method prints out TRANSFORMATION_FAILED_FLAG if something went wrong.
*
* @param args Command line arguments passed by a user in step 1 of the Workaround.
*/
public static void main(String[] args) {
PrintStream ps = null;
try {
String encoding = System.getProperty("file.encoding", Charset.defaultCharset().name());
ps = new PrintStream(System.out, true, encoding);
ps.println(transform(args));
}
catch (Throwable t) {
t.printStackTrace();
if (ps != null)
ps.println(TRANSFORMATION_FAILED_FLAG);
if (t instanceof Error)
throw (Error)t;
}
}
代码示例来源:origin: stackoverflow.com
public static StreamEncoder forOutputStreamWriter(OutputStream out,
Object lock,
String charsetName)
throws UnsupportedEncodingException
{
String csn = charsetName;
if (csn == null)
csn = Charset.defaultCharset().name();
try {
if (Charset.isSupported(csn))
return new StreamEncoder(out, lock, Charset.forName(csn));
} catch (IllegalCharsetNameException x) { }
throw new UnsupportedEncodingException (csn);
}
代码示例来源:origin: apache/storm
public static List<String> readFileByLine(String filePath) throws IOException {
return Files.readLines(new File(filePath), Charset.defaultCharset());
}
代码示例来源:origin: sleekbyte/tailor
@Before
public void setUp() throws IOException {
inputFile = new File(TEST_INPUT_DIR + "/UpperCamelCaseTest.swift");
expectedMessages = new ArrayList<>();
outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent, false, Charset.defaultCharset().name()));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void sameEncoding_CharsetEncoder_constructor() throws Exception {
final CharsetEncoder enc = Charset.defaultCharset().newEncoder();
succesfulRun(new FileWriterWithEncoding(file2, enc));
}
代码示例来源:origin: checkstyle/checkstyle
@Test
public void testGetLine() throws Exception {
final AbstractCheck check = new AbstractCheck() {
@Override
public int[] getDefaultTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}
@Override
public int[] getAcceptableTokens() {
return getDefaultTokens();
}
@Override
public int[] getRequiredTokens() {
return getDefaultTokens();
}
};
check.setFileContents(new FileContents(new FileText(
new File(getPath("InputAbstractCheckTestFileContents.java")),
Charset.defaultCharset().name())));
Assert.assertEquals("Invalid line content", " * I'm a javadoc", check.getLine(3));
}
代码示例来源:origin: runelite/runelite
@Test
public void extract() throws IOException
{
File base = StoreLocation.LOCATION,
outDir = folder.newFolder();
int count = 0;
try (Store store = new Store(base))
{
store.load();
AreaManager areaManager = new AreaManager(store);
areaManager.load();
for (AreaDefinition area : areaManager.getAreas())
{
Files.write(gson.toJson(area), new File(outDir, area.id + ".json"), Charset.defaultCharset());
++count;
}
}
logger.info("Dumped {} areas to {}", count, outDir);
}
}
内容来源于网络,如有侵权,请联系作者删除!