本文整理汇总了Java中java.nio.charset.Charset.name方法的典型用法代码示例。如果您正苦于以下问题:Java Charset.name方法的具体用法?Java Charset.name怎么用?Java Charset.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.Charset
的用法示例。
在下文中一共展示了Charset.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProjectEncodingAsString
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Get the encoding of the supplied project as a String (by performing a lookup and invoking Charset.name).
* @param project The project
* @param file A file in the project
* @return The project encoding, or a suitable default if the project encoding cannot be determined. Never null
*/
public static String getProjectEncodingAsString(Project project, FileObject file) {
Charset encoding = project.getLookup().lookup(FileEncodingQueryImplementation.class).getEncoding(file);
if (encoding == null) {
encoding = FileEncodingQuery.getDefaultEncoding();
if (encoding == null) {
return "UTF-8";
}
else {
return encoding.name();
}
}
else {
return encoding.name();
}
}
示例2: detectingCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static String detectingCharset(byte[] bytes) throws Exception {
//----------------------------------------------------------------
// Test special public methods of CharsetDecoder while we're here
//----------------------------------------------------------------
CharsetDecoder cd = Charset.forName("JISAutodetect").newDecoder();
check(cd.isAutoDetecting(), "isAutodecting()");
check(! cd.isCharsetDetected(), "isCharsetDetected");
cd.decode(ByteBuffer.wrap(new byte[] {(byte)'A'}));
check(! cd.isCharsetDetected(), "isCharsetDetected");
try {
cd.detectedCharset();
fail("no IllegalStateException");
} catch (IllegalStateException e) {}
cd.decode(ByteBuffer.wrap(bytes));
check(cd.isCharsetDetected(), "isCharsetDetected");
Charset cs = cd.detectedCharset();
check(cs != null, "cs != null");
check(! cs.newDecoder().isAutoDetecting(), "isAutodetecting()");
return cs.name();
}
示例3: HttpStatusCodeException
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Construct a new instance of {@code HttpStatusCodeException} based on an
* {@link HttpStatus}, status text, and response body content.
* @param statusCode the status code
* @param statusText the status text
* @param responseHeaders the response headers, may be {@code null}
* @param responseBody the response body content, may be {@code null}
* @param responseCharset the response body charset, may be {@code null}
* @since 3.1.2
*/
protected HttpStatusCodeException(HttpStatus statusCode, String statusText,
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
super(statusCode.value() + " " + statusText);
this.statusCode = statusCode;
this.statusText = statusText;
this.responseHeaders = responseHeaders;
this.responseBody = responseBody != null ? responseBody : new byte[0];
this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET;
}
示例4: setContent
import java.nio.charset.Charset; //导入方法依赖的package包/类
public void setContent(final String source, final ContentType contentType) throws UnsupportedCharsetException {
Args.notNull(source, "Source string");
Charset charset = contentType != null?contentType.getCharset():null;
if(charset == null) {
charset = HTTP.DEF_CONTENT_CHARSET;
}
try {
this.content = new BytesArray(source.getBytes(charset.name()));
} catch (UnsupportedEncodingException var) {
throw new UnsupportedCharsetException(charset.name());
}
if(contentType != null) {
addHeader("Content-Type", contentType.toString());
}
}
示例5: StringEntity
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Creates a StringEntity with the specified content and content type.
*
* @param string content to be used. Not {@code null}.
* @param contentType content type to be used. May be {@code null}, in which case the default
* MIME type {@link ContentType#TEXT_PLAIN} is assumed.
*
* @throws IllegalArgumentException if the string parameter is null
* @throws UnsupportedCharsetException Thrown when the named charset is not available in
* this instance of the Java virtual machine
* @since 4.2
*/
public StringEntity(final String string, final ContentType contentType) throws UnsupportedCharsetException {
super();
Args.notNull(string, "Source string");
Charset charset = contentType != null ? contentType.getCharset() : null;
if (charset == null) {
charset = HTTP.DEF_CONTENT_CHARSET;
}
try {
this.content = string.getBytes(charset.name());
} catch (final UnsupportedEncodingException ex) {
// should never happen
throw new UnsupportedCharsetException(charset.name());
}
if (contentType != null) {
setContentType(contentType.toString());
}
}
示例6: UnknownHttpStatusCodeException
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Construct a new instance of {@code HttpStatusCodeException} based on an
* {@link HttpStatus}, status text, and response body content.
* @param rawStatusCode the raw status code value
* @param statusText the status text
* @param responseHeaders the response headers, may be {@code null}
* @param responseBody the response body content, may be {@code null}
* @param responseCharset the response body charset, may be {@code null}
*/
public UnknownHttpStatusCodeException(int rawStatusCode, String statusText,
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
super("Unknown status code [" + String.valueOf(rawStatusCode) + "]" + " " + statusText);
this.rawStatusCode = rawStatusCode;
this.statusText = statusText;
this.responseHeaders = responseHeaders;
this.responseBody = responseBody != null ? responseBody : new byte[0];
this.responseCharset = responseCharset != null ? responseCharset.name() : DEFAULT_CHARSET;
}
示例7: ensureProjectAttrs
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static void ensureProjectAttrs(Map<String, Object> map, FileObject parent) {
if (map.get(ATTR_LICENSE) == null) {
map.put(ATTR_LICENSE, "default"); // NOI18N
}
if (map.get(ATTR_LICENSE_PATH) == null) {
map.put(ATTR_LICENSE_PATH, "Templates/Licenses/license-" + map.get(ATTR_LICENSE).toString() + ".txt"); // NOI18N
}
String url = map.get(ATTR_LICENSE_PATH).toString();
if (FileUtil.getConfigFile(url) == null) { //now we have filesystem based template for sure, convert to file:///path to have freemarker process it
try {
URI uri = URI.create(url);
//freemarker.cache.TemplateCache.normalizeName appears to
// check for :// to skip processing the path
map.put(ATTR_LICENSE_PATH, new URI("file", "", uri.getPath(), null).toString());
} catch (Exception malformedURLException) {
}
} else {
// now we have to assume we are dealing with the teplate from system filesystem.
// in order to get through the freemarker, the path needs to "absolute" in freemarker terms - http://freemarker.sourceforge.net/docs/ref_directive_include.html
// relative would mean relative to the template and we cannot be sure what the path from template to license template is..
// it used to be, ../Licenses/ or ../../Licenses but can be anything similar, just based on where the template resides.
map.put(ATTR_LICENSE_PATH, "/" + url);
//appears to cover both the new and old default value of the include path
}
if (map.get(ATTR_ENCODING) == null) {
Charset charset = FileEncodingQuery.getEncoding(parent);
String encoding = charset != null ? charset.name() : "UTF-8"; // NOI18N
map.put(ATTR_ENCODING, encoding);
}
}
示例8: getCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
String getCharset() {
Charset charset = info.getCharset();
if (charset != null) {
return charset.name();
}
return null;
}
示例9: FontDescriptor
import java.nio.charset.Charset; //导入方法依赖的package包/类
public FontDescriptor(String nativeName, CharsetEncoder encoder,
int[] exclusionRanges){
this.nativeName = nativeName;
this.encoder = encoder;
this.exclusionRanges = exclusionRanges;
this.useUnicode = false;
Charset cs = encoder.charset();
if (cs instanceof HistoricallyNamedCharset)
this.charsetName = ((HistoricallyNamedCharset)cs).historicalName();
else
this.charsetName = cs.name();
}
示例10: 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
*/
@Override
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();
}
示例11: convertTabs
import java.nio.charset.Charset; //导入方法依赖的package包/类
private static byte[] convertTabs(byte[] bytes, Charset charset, int replaceTabs) throws Exception
{
// The tab character
char tab = '\t';
char space = ' ';
// The output
StringBuilder sb = new StringBuilder(bytes.length);
String charsetName = charset.name();
// Using the charset, convert to a string
String str = new String(bytes, charsetName);
char[] chars = str.toCharArray();
for (char c : chars)
{
if (c == tab)
{
// Replace the tab
for (int i = 0; i < replaceTabs; i++)
{
sb.append(space);
}
}
else
{
sb.append(c);
}
}
// Done
return sb.toString().getBytes(charsetName);
}
示例12: readDocument
import java.nio.charset.Charset; //导入方法依赖的package包/类
ACHDocument readDocument(InputStream is, Charset charset) {
Scanner sc = new Scanner(is, charset.name());
while (sc.hasNextLine()) {
++lineNumber;
currentLine = sc.nextLine();
validateString();
ACHRecord record = readRecord(currentLine, findRecordType())
.setLineNumber(lineNumber);
if (record.is(FILE_HEADER)) {
document.setFileHeader((FileHeader) record);
} else if (record.is(FILE_CONTROL)) {
document.setFileControl((FileControl) record);
return returnDocument();
} else if (record.is(BATCH_HEADER)) {
currentBatch = new ACHBatch().setBatchHeader((BatchHeader) record);
document.addBatch(currentBatch);
} else if (record.is(BATCH_CONTROL)) {
currentBatch.setBatchControl((BatchControl) record);
currentBatch = null;
currentDetail = null;
} else if (record.is(ENTRY_DETAIL)) {
currentDetail = new ACHBatchDetail()
.setDetailRecord((EntryDetail) record);
currentBatch.addDetail(currentDetail);
} else if (record.is(ADDENDA)) {
currentDetail.addAddendaRecord((AddendaRecord) record);
}
}
return returnDocument();
}
示例13: testLeftoverSize
import java.nio.charset.Charset; //导入方法依赖的package包/类
@Test
public void testLeftoverSize() {
float maxLeftover = 0;
String charsetName = "UNSET";
for (Charset charset : Charset.availableCharsets().values()) {
float leftover;
if (charset.name().toLowerCase(Locale.ENGLISH).startsWith("x-")) {
// Non-standard charset that browsers won't be using
// Likely something used internally by the JRE
continue;
}
if (charset.name().equals("COMPOUND_TEXT")) {
// Java for-internal-use-only charset
// See:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6392670
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6381697
continue;
}
try {
leftover = charset.newEncoder().maxBytesPerChar();
} catch (UnsupportedOperationException uoe) {
// Skip it
continue;
}
if (leftover > maxLeftover) {
maxLeftover = leftover;
charsetName = charset.name();
}
}
Assert.assertTrue("Limit needs to be at least " + maxLeftover +
" (used in charset '" + charsetName + "')",
maxLeftover <= B2CConverter.LEFTOVER_SIZE);
}
示例14: SerializedForm
import java.nio.charset.Charset; //导入方法依赖的package包/类
SerializedForm(Charset charset) {
this.charsetCanonicalName = charset.name();
}
示例15: getCharset
import java.nio.charset.Charset; //导入方法依赖的package包/类
public static String getCharset(HttpResponse response) {
ContentType contentType = ContentType.getOrDefault(response.getEntity());
Charset charset = contentType.getCharset();
return charset == null ? "UTF-8" : charset.name();
}