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


Java Charset.forName方法代碼示例

本文整理匯總了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;
	}
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:25,代碼來源:UKResultMapper.java

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

}
 
開發者ID:wenzhifeifeidetutu,項目名稱:QuakeRepor,代碼行數:17,代碼來源:Query.java

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

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

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:CodeSetConversion.java

示例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);
     }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:BufferedCharSequenceTest.java

示例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"));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:12,代碼來源:ClusterCLI.java

示例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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:39,代碼來源:XMLFormatter.java

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

示例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);
	}
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:10,代碼來源:AllTests.java

示例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);
}
 
開發者ID:rvillars,項目名稱:edoras-one-initializr,代碼行數:8,代碼來源:TemplateRenderer.java

示例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);
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:9,代碼來源:ZookeeperWatchTrigger.java

示例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"))));
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:77,代碼來源:DeleteDocumentation.java

示例14: getCharset

import java.nio.charset.Charset; //導入方法依賴的package包/類
private Charset getCharset(String encoding) {
    return (encoding == null) ? Charset.defaultCharset() : Charset.forName(encoding);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:ToolBox.java

示例15: setCharset

import java.nio.charset.Charset; //導入方法依賴的package包/類
public void setCharset(String charset) {
    this.charset = Charset.forName(charset);
}
 
開發者ID:NymphWeb,項目名稱:nymph,代碼行數:4,代碼來源:HttpChannel.java


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