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


Java Charset.name方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:JpaControllerUtil.java

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

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:HttpStatusCodeException.java

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

示例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());
    }
}
 
開發者ID:mozilla-mobile,項目名稱:FirefoxData-android,代碼行數:30,代碼來源:StringEntity.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:UnknownHttpStatusCodeException.java

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

示例8: getCharset

import java.nio.charset.Charset; //導入方法依賴的package包/類
String getCharset() {
    Charset charset = info.getCharset();
    if (charset != null) {
        return charset.name();
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:AbstractNativeProcess.java

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

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:FontDescriptor.java

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

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:32,代碼來源:Convert.java

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

示例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);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:34,代碼來源:TestB2CConverter.java

示例14: SerializedForm

import java.nio.charset.Charset; //導入方法依賴的package包/類
SerializedForm(Charset charset) {
  this.charsetCanonicalName = charset.name();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:4,代碼來源:Funnels.java

示例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();
}
 
開發者ID:EHRI,項目名稱:rs-aggregator,代碼行數:6,代碼來源:AbstractUriReader.java


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