本文整理了Java中java.nio.charset.Charset.name()
方法的一些代码示例,展示了Charset.name()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Charset.name()
方法的具体详情如下:
包路径:java.nio.charset.Charset
类名称:Charset
方法名:name
[英]Returns the canonical name of this charset.
If a charset is in the IANA registry, this will be the MIME-preferred name (a charset may have multiple IANA-registered names). Otherwise the canonical name will begin with "x-" or "X-".
[中]返回此字符集的规范名称。
如果IANA注册表中有一个字符集,这将是MIME首选名称(一个字符集可能有多个IANA注册名称)。否则,规范名称将以“x-”或“x-”开头。
代码示例来源:origin: jenkinsci/jenkins
public String call() throws IOException {
return Charset.defaultCharset().name();
}
}
代码示例来源:origin: apache/hive
@Override
public String encode(String key) {
try {
return URLEncoder.encode(key, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
return key;
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public String toString()
{
try
{
baos.flush();
return baos.toString( StandardCharsets.UTF_8.name() );
}
catch ( Exception e )
{
throw new RuntimeException( e );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public static String serialize( StepMetaProps stepMetaProps ) {
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
Marshaller marshalObj = JAXBContext.newInstance( StepMetaProps.class ).createMarshaller();
marshalObj.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
marshalObj.setProperty( Marshaller.JAXB_FRAGMENT, true );
marshalObj.marshal( stepMetaProps, baos );
return baos.toString( defaultCharset().name() );
} catch ( JAXBException | IOException e ) {
throw new RuntimeException( e );
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testStandardCharsetsEquality() throws Exception {
assertEquals(StandardCharsets.ISO_8859_1.name(), CharEncoding.ISO_8859_1);
assertEquals(StandardCharsets.US_ASCII.name(), CharEncoding.US_ASCII);
assertEquals(StandardCharsets.UTF_8.name(), CharEncoding.UTF_8);
assertEquals(StandardCharsets.UTF_16.name(), CharEncoding.UTF_16);
assertEquals(StandardCharsets.UTF_16BE.name(), CharEncoding.UTF_16BE);
assertEquals(StandardCharsets.UTF_16LE.name(), CharEncoding.UTF_16LE);
}
}
代码示例来源:origin: biezhi/30-seconds-of-java8
public static String convertInputStreamToString(final InputStream in) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
}
代码示例来源:origin: spring-projects/spring-framework
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
Writer writer = new OutputStreamWriter(bos, FORM_CHARSET);
for (Iterator<String> valueIterator = values.iterator(); valueIterator.hasNext();) {
String value = valueIterator.next();
writer.write(URLEncoder.encode(name, FORM_CHARSET.name()));
if (value != null) {
writer.write('=');
writer.write(URLEncoder.encode(value, FORM_CHARSET.name()));
if (valueIterator.hasNext()) {
writer.write('&');
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRequireValidAuthorizationHeader() throws Exception
{
// Given
final AuthorizationEnabledFilter filter = new AuthorizationEnabledFilter( () -> authManager, logProvider );
when( servletRequest.getMethod() ).thenReturn( "GET" );
when( servletRequest.getContextPath() ).thenReturn( "/db/data" );
when( servletRequest.getHeader( HttpHeaders.AUTHORIZATION ) ).thenReturn( "NOT A VALID VALUE" );
// When
filter.doFilter( servletRequest, servletResponse, filterChain );
// Then
verifyNoMoreInteractions( filterChain );
verify( servletResponse ).setStatus( 400 );
verify( servletResponse ).addHeader( HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8" );
assertThat( outputStream.toString( StandardCharsets.UTF_8.name() ),
containsString( "\"code\" : \"Neo.ClientError.Request.InvalidFormat\"" ) );
assertThat( outputStream.toString( StandardCharsets.UTF_8.name() ),
containsString( "\"message\" : \"Invalid authentication header.\"" ) );
}
代码示例来源:origin: checkstyle/checkstyle
@Test
public void testProcessNonJavaFilesWithoutException() throws Exception {
final TreeWalker treeWalker = new TreeWalker();
treeWalker.setTabWidth(1);
treeWalker.configure(new DefaultConfiguration("default config"));
final File file = new File(getPath("InputTreeWalkerNotJava.xml"));
final FileText fileText = new FileText(file, StandardCharsets.ISO_8859_1.name());
treeWalker.processFiltered(file, fileText);
final Collection<Checks> checks = Whitebox.getInternalState(treeWalker, "ordinaryChecks");
assertTrue("No checks -> No parsing", checks.isEmpty());
}
代码示例来源:origin: dreamhead/moco
public static boolean isValidUrl(final String url) {
try {
String encodedURL = URLEncoder.encode(url, Charset.defaultCharset().name());
return url.equals(encodedURL);
} catch (UnsupportedEncodingException e) {
return false;
}
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSerializeResponseWithNoCommitUriResultsOrErrors() throws Exception
{
// given
ByteArrayOutputStream output = new ByteArrayOutputStream();
ExecutionResultSerializer serializer = getSerializerWith( output );
// when
serializer.finish();
// then
String result = output.toString( UTF_8.name() );
assertEquals( "{\"results\":[],\"errors\":[]}", result );
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testUtf16() {
Assert.assertEquals("UTF-16", Charsets.UTF_16.name());
}
代码示例来源:origin: redisson/redisson
private static String readContent(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte[] buf = new byte[8192];
for (;;) {
int ret = in.read(buf);
if (ret < 0) {
break;
}
out.write(buf, 0, ret);
}
return out.toString(CharsetUtil.US_ASCII.name());
} finally {
safeClose(out);
}
}
代码示例来源:origin: twitter/distributedlog
public static String getLockPathPrefixV2(String lockPath, String clientId) throws UnsupportedEncodingException {
// member_<clientid>_
return lockPath + LOCK_PATH_PREFIX + URLEncoder.encode(clientId, UTF_8.name()) + LOCK_PART_SEP;
}
代码示例来源:origin: jenkinsci/jenkins
public String call() throws IOException {
return Charset.defaultCharset().name();
}
代码示例来源:origin: neo4j/neo4j
@Override
public String toString()
{
try
{
return voiceStream.toString( StandardCharsets.UTF_8.name() );
}
catch ( UnsupportedEncodingException e )
{
throw new RuntimeException( e );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSerializeResponseWithCommitUriOnly() throws Exception
{
// given
ByteArrayOutputStream output = new ByteArrayOutputStream();
ExecutionResultSerializer serializer = getSerializerWith( output );
// when
serializer.transactionCommitUri( URI.create( "commit/uri/1" ) );
serializer.finish();
// then
String result = output.toString( UTF_8.name() );
assertEquals( "{\"commit\":\"commit/uri/1\",\"results\":[],\"errors\":[]}", result );
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testUtf16Be() {
Assert.assertEquals("UTF-16BE", Charsets.UTF_16BE.name());
}
代码示例来源:origin: javamelody/javamelody
public static String pumpToString(InputStream input, Charset charset) throws IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
pump(input, out);
return out.toString(charset.name());
}
代码示例来源:origin: neo4j/neo4j
public static String encode( String value )
{
try
{
return URLEncoder.encode( value, StandardCharsets.UTF_8.name() )
.replaceAll( "\\+", "%20" );
}
catch ( UnsupportedEncodingException e )
{
throw new RuntimeException( e );
}
}
}
内容来源于网络,如有侵权,请联系作者删除!