本文整理汇总了Java中java.nio.charset.Charset.forName方法的典型用法代码示例。如果您正苦于以下问题:Java Charset.forName方法的具体用法?Java Charset.forName怎么用?Java Charset.forName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.Charset
的用法示例。
在下文中一共展示了Charset.forName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildJSONFromFields
import java.nio.charset.Charset; //导入方法依赖的package包/类
private String buildJSONFromFields(Collection<SearchHitField> values) {
JsonFactory nodeFactory = new JsonFactory();
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
generator.writeStartObject();
for (SearchHitField value : values) {
if (value.getValues().size() > 1) {
generator.writeArrayFieldStart(value.getName());
for (Object val : value.getValues()) {
generator.writeObject(val);
}
generator.writeEndArray();
} else {
generator.writeObjectField(value.getName(), value.getValue());
}
}
generator.writeEndObject();
generator.flush();
return new String(stream.toByteArray(), Charset.forName("UTF-8"));
} catch (IOException e) {
return null;
}
}
示例2: readFromSream
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static String readFromSream(InputStream inputStream) throws IOException {
//采用StringBuilder来进行流处理
StringBuilder output = new StringBuilder();
if (inputStream !=null){
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
BufferedReader reader = new BufferedReader(inputStreamReader);
String line = reader.readLine();
while (line !=null){
output.append(line);
line =reader.readLine();
}
}
return output.toString();
}
示例3: getCharsetByName
import java.nio.charset.Charset; //导入方法依赖的package包/类
public static Charset getCharsetByName(String charsetName) throws IllegalArgumentException {
// On Windows 10, cp65001 is the UTF-8 code page. For some reason, popular JVMs don't
// have a mapping for cp65001...
if ("cp65001".equalsIgnoreCase(charsetName)) {
return StandardCharsets.UTF_8;
}
return Charset.forName(charsetName);
}
示例4: isPostscript
import java.nio.charset.Charset; //导入方法依赖的package包/类
public synchronized boolean isPostscript() {
if (isPS == null) {
isPS = Boolean.TRUE;
if (isCupsPrinter) {
try {
urlConnection = getIPPConnection(
new URL(myURL+".ppd"));
InputStream is = urlConnection.getInputStream();
if (is != null) {
BufferedReader d =
new BufferedReader(new InputStreamReader(is,
Charset.forName("ISO-8859-1")));
String lineStr;
while ((lineStr = d.readLine()) != null) {
if (lineStr.startsWith("*cupsFilter:")) {
isPS = Boolean.FALSE;
break;
}
}
}
} catch (java.io.IOException e) {
debug_println(" isPostscript, e= "+e);
/* if PPD is not found, this may be a raw printer
and in this case it is assumed that it is a
Postscript printer */
// do nothing
}
}
}
return isPS.booleanValue();
}
示例5: JavaCTBConverter
import java.nio.charset.Charset; //导入方法依赖的package包/类
public JavaCTBConverter(OSFCodeSetRegistry.Entry codeset,
int alignmentForEncoding) {
try {
ctb = cache.getCharToByteConverter(codeset.getName());
if (ctb == null) {
Charset tmpCharset = Charset.forName(codeset.getName());
ctb = tmpCharset.newEncoder();
cache.setConverter(codeset.getName(), ctb);
}
} catch(IllegalCharsetNameException icne) {
// This can only happen if one of our Entries has
// an invalid name.
throw wrapper.invalidCtbConverterName(icne,codeset.getName());
} catch(UnsupportedCharsetException ucne) {
// This can only happen if one of our Entries has
// an unsupported name.
throw wrapper.invalidCtbConverterName(ucne,codeset.getName());
}
this.codeset = codeset;
alignment = alignmentForEncoding;
}
示例6: getFile
import java.nio.charset.Charset; //导入方法依赖的package包/类
@Test
public void testCharAt$10_byte() {
System.out.println("testCharAt$10_byte");
File file = getFile("10_bytes");
Charset cs = Charset.forName(UTF_8);
for(TypeOfStream stype: TypeOfStream.values()) {
InputStream stream = getInputStream(stype, TypeOfContent.BYTE_10, cs);
BufferedCharSequence instance = new BufferedCharSequence(stream, cs.newDecoder(), 10);
instance.setMaxBufferSize(10);
char result;
result = instance.charAt(0);
assertEquals('0', result);
result = instance.charAt(9);
assertEquals('9', result);
result = instance.charAt(5);
assertEquals('5', result);
result = instance.charAt(9);
assertEquals('9', result);
}
}
示例7: printUsage
import java.nio.charset.Charset; //导入方法依赖的package包/类
@VisibleForTesting
void printUsage(Options opts) throws UnsupportedEncodingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw =
new PrintWriter(new OutputStreamWriter(baos, Charset.forName("UTF-8")));
new HelpFormatter().printHelp(pw, HelpFormatter.DEFAULT_WIDTH, TITLE, null,
opts, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD,
null);
pw.close();
sysout.println(baos.toString("UTF-8"));
}
示例8: getHead
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Return the header string for a set of XML formatted records.
*
* @param h The target handler (can be null)
* @return a valid XML string
*/
public String getHead(Handler h) {
StringBuilder sb = new StringBuilder();
String encoding;
sb.append("<?xml version=\"1.0\"");
if (h != null) {
encoding = h.getEncoding();
} else {
encoding = null;
}
if (encoding == null) {
// Figure out the default encoding.
encoding = java.nio.charset.Charset.defaultCharset().name();
}
// Try to map the encoding name to a canonical name.
try {
Charset cs = Charset.forName(encoding);
encoding = cs.name();
} catch (Exception ex) {
// We hit problems finding a canonical name.
// Just use the raw encoding name.
}
sb.append(" encoding=\"");
sb.append(encoding);
sb.append("\"");
sb.append(" standalone=\"no\"?>\n");
sb.append("<!DOCTYPE log SYSTEM \"logger.dtd\">\n");
sb.append("<log>\n");
return sb.toString();
}
示例9: getCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
private Charset getCharset() {
try {
return Charset.forName(encoding);
} catch (UnsupportedCharsetException exception) {
Charset defaultCharset = Charset.defaultCharset();
return defaultCharset;
}
}
示例10: test112
import java.nio.charset.Charset; //导入方法依赖的package包/类
@Test
public void test112() throws Exception {
try {
new CsvWriter((String) null, ',', Charset
.forName("ISO-8859-1"));
} catch (Exception ex) {
assertException(new IllegalArgumentException("Parameter fileName can not be null."), ex);
}
}
示例11: mustacheTemplateLoader
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static TemplateLoader mustacheTemplateLoader() {
ResourceLoader resourceLoader = new DefaultResourceLoader();
String prefix = "classpath:/templates/";
Charset charset = Charset.forName("UTF-8");
return name -> new InputStreamReader(
resourceLoader.getResource(prefix + name).getInputStream(), charset);
}
示例12: getTriggerEvent
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Create a trigger event from the provided data.
* @return Trigger event
*/
private TriggerEvent getTriggerEvent(final byte[] data) {
final String json = new String(data, Charset.forName("UTF-8"));
return getTriggerEventFromJson(json);
}
示例13: deleteReleaseDefault
import java.nio.charset.Charset; //导入方法依赖的package包/类
@Test
public void deleteReleaseDefault() throws Exception {
final String releaseName = "myLogRelease1";
final InstallRequest installRequest = new InstallRequest();
final PackageIdentifier packageIdentifier = new PackageIdentifier();
packageIdentifier.setPackageName("log");
packageIdentifier.setPackageVersion("1.0.0");
packageIdentifier.setRepositoryName("notused");
installRequest.setPackageIdentifier(packageIdentifier);
installRequest.setInstallProperties(createInstallProperties(releaseName));
installPackage(installRequest);
final MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(),
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
this.mockMvc.perform(
delete("/api/release/{releaseName}", releaseName)
.accept(MediaType.APPLICATION_JSON).contentType(contentType))
.andDo(print())
.andExpect(status().isOk())
.andDo(this.documentationHandler.document(
responseFields(
subsectionWithPath("links").ignored(),
fieldWithPath("name").description("Name of the release"),
fieldWithPath("version").description("Version of the release"),
fieldWithPath("info.status.statusCode").description(
String.format("StatusCode of the release's status (%s)",
StringUtils.arrayToCommaDelimitedString(StatusCode.values()))),
fieldWithPath("info.status.platformStatus")
.description("Status from the underlying platform"),
fieldWithPath("info.firstDeployed").description("Date/Time of first deployment"),
fieldWithPath("info.lastDeployed").description("Date/Time of last deployment"),
fieldWithPath("info.deleted").description("Date/Time of when the release was deleted"),
fieldWithPath("info.description")
.description("Human-friendly 'log entry' about this release"),
fieldWithPath("pkg.metadata.apiVersion")
.description("The Package Index spec version this file is based on"),
fieldWithPath("pkg.metadata.origin")
.description("Indicates the origin of the repository (free form text)"),
fieldWithPath("pkg.metadata.repositoryId")
.description("The repository ID this Package belongs to."),
fieldWithPath("pkg.metadata.repositoryName")
.description("The repository name this Package belongs to."),
fieldWithPath("pkg.metadata.kind")
.description("What type of package system is being used"),
fieldWithPath("pkg.metadata.name").description("The name of the package"),
fieldWithPath("pkg.metadata.displayName").description("Display name of the release"),
fieldWithPath("pkg.metadata.version").description("The version of the package"),
fieldWithPath("pkg.metadata.packageSourceUrl")
.description("Location to source code for this package"),
fieldWithPath("pkg.metadata.packageHomeUrl")
.description("The home page of the package"),
fieldWithPath("pkg.metadata.tags")
.description("A comma separated list of tags to use for searching"),
fieldWithPath("pkg.metadata.maintainer").description("Who is maintaining this package"),
fieldWithPath("pkg.metadata.description")
.description("Brief description of the package"),
fieldWithPath("pkg.metadata.sha256").description(
"Hash of package binary that will be downloaded using SHA256 hash algorithm"),
fieldWithPath("pkg.metadata.iconUrl").description("Url location of a icon"),
fieldWithPath("pkg.templates[].name")
.description("Name is the path-like name of the template"),
fieldWithPath("pkg.templates[].data")
.description("Data is the template as string data"),
fieldWithPath("pkg.dependencies")
.description("The packages that this package depends upon"),
fieldWithPath("pkg.configValues.raw")
.description("The raw YAML string of configuration values"),
fieldWithPath("pkg.fileHolders")
.description("Miscellaneous files in a package, e.g. README, LICENSE, etc."),
fieldWithPath("configValues.raw")
.description("The raw YAML string of configuration values"),
fieldWithPath("manifest.data").description("The manifest of the release"),
fieldWithPath("platformName").description("Platform name of the release"))));
}
示例14: getCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
private Charset getCharset(String encoding) {
return (encoding == null) ? Charset.defaultCharset() : Charset.forName(encoding);
}
示例15: setCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
public void setCharset(String charset) {
this.charset = Charset.forName(charset);
}