当前位置: 首页>>代码示例>>Java>>正文


Java CharsetEncoder.canEncode方法代码示例

本文整理汇总了Java中java.nio.charset.CharsetEncoder.canEncode方法的典型用法代码示例。如果您正苦于以下问题:Java CharsetEncoder.canEncode方法的具体用法?Java CharsetEncoder.canEncode怎么用?Java CharsetEncoder.canEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.charset.CharsetEncoder的用法示例。


在下文中一共展示了CharsetEncoder.canEncode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newFixedLengthResponse

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
/**
 * Create a text response with known length.
 */
public static Response newFixedLengthResponse(IStatus status, String mimeType, String txt) {
    ContentType contentType = new ContentType(mimeType);
    if (txt == null) {
        return newFixedLengthResponse(status, mimeType, new ByteArrayInputStream(new byte[0]), 0);
    } else {
        byte[] bytes;
        try {
            CharsetEncoder newEncoder = Charset.forName(contentType.getEncoding()).newEncoder();
            if (!newEncoder.canEncode(txt)) {
                contentType = contentType.tryUTF8();
            }
            bytes = txt.getBytes(contentType.getEncoding());
        } catch (UnsupportedEncodingException e) {
            NanoHTTPD.LOG.log(Level.SEVERE, "encoding problem, responding nothing", e);
            bytes = new byte[0];
        }
        return newFixedLengthResponse(status, contentType.getContentTypeHeader(), new ByteArrayInputStream(bytes), bytes.length);
    }
}
 
开发者ID:xm0625,项目名称:VBrowser-Android,代码行数:23,代码来源:NanoHTTPD.java

示例2: checkCharsetConversion

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
private boolean checkCharsetConversion(final String encoding) {
    boolean value = true;
    try {
        CharsetEncoder coder = Charset.forName(encoding).newEncoder();
        if (!coder.canEncode(getDocument().getText(0, getDocument().getLength()))){
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
                    NbBundle.getMessage(XmlMultiViewEditorSupport.class, "MSG_BadCharConversion",
                    new Object [] { getDataObject().getPrimaryFile().getNameExt(),
                    encoding}),
                    NotifyDescriptor.YES_NO_OPTION,
                    NotifyDescriptor.WARNING_MESSAGE);
            nd.setValue(NotifyDescriptor.NO_OPTION);
            DialogDisplayer.getDefault().notify(nd);
            if(nd.getValue() != NotifyDescriptor.YES_OPTION) {
                value = false;
            }
        }
    } catch (BadLocationException e){
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
    }
    return value;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:XmlMultiViewEditorSupport.java

示例3: newFixedLengthResponse

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
public static Response newFixedLengthResponse(Response.IStatus status, String mimeType, String txt) {
    ContentType contentType = new ContentType(mimeType);
    if (txt == null) {
        return newFixedLengthResponse(status, mimeType, new ByteArrayInputStream(new byte[0]), 0);
    } else {
        byte[] bytes;
        try {
            CharsetEncoder newEncoder = Charset.forName(contentType.getEncoding()).newEncoder();
            if (!newEncoder.canEncode(txt)) {
                contentType = contentType.tryUTF8();
            }
            bytes = txt.getBytes(contentType.getEncoding());
        } catch (UnsupportedEncodingException e) {
            NanoHTTPD.LOG.log(Level.SEVERE, "encoding problem, responding nothing", e);
            bytes = new byte[0];
        }
        return newFixedLengthResponse(status, contentType.getContentTypeHeader(), new ByteArrayInputStream(bytes), bytes.length);
    }
}
 
开发者ID:ZavixDragon,项目名称:LiteJavaWebsite,代码行数:20,代码来源:NanoHTTPD.java

示例4: canBeEncoded

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
/**
 * Check the value can be encoded with the specified encoding
 * @return
 */
public boolean canBeEncoded()
{
    //Try and write to buffer using the CharSet defined by the textEncoding field (note if using UTF16 we dont
    //need to worry about LE,BE at this point it makes no difference)
    final byte textEncoding = this.getBody().getTextEncoding();
    final TextEncoding encoding = TextEncoding.getInstanceOf();
    final Charset charset = encoding.getCharsetForId(textEncoding);
    CharsetEncoder encoder = charset.newEncoder();

    if (encoder.canEncode((String) value))
    {
        return true;
    }
    else
    {
        logger.finest("Failed Trying to decode" + value + "with" + encoder.toString());
        return false;
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:24,代码来源:AbstractString.java

示例5: write

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
/**
 * If the description cannot be encoded using the current encoding change the encoder
 */
public void write(ByteArrayOutputStream tagBuffer)
{
    CharsetEncoder encoder = StandardCharsets.ISO_8859_1.newEncoder();
    String origUrl = getUrlLink();
    if (!encoder.canEncode(origUrl))
    {
        //ALL W Frames only support ISO-8859-1 for the url itself, if unable to encode let us assume
        //the link just needs url encoding
        setUrlLink(encodeURL(origUrl));

        //We still cant convert so just set log error and set to blank to allow save to continue
        if (!encoder.canEncode(getUrlLink()))
        {
            logger.warning(ErrorMessage.MP3_UNABLE_TO_ENCODE_URL.getMsg(origUrl));
            setUrlLink("");
        }
        //it was ok, just note the modification made
        else
        {
            logger.warning(ErrorMessage.MP3_URL_SAVED_ENCODED.getMsg(origUrl, getUrlLink()));
        }
    }
    super.write(tagBuffer);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:28,代码来源:AbstractFrameBodyUrlLink.java

示例6: newFixedLengthResponse

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
/**
 * 创建一个已知大小的(超)文本相应
 */
public static Response newFixedLengthResponse(Response.IStatus status, String mimeType, String txt) {
    ContentType contentType = new ContentType(mimeType);
    if (txt == null) {
        return newFixedLengthResponse(status, mimeType, new ByteArrayInputStream(new byte[0]), 0);
    } else {
        byte[] bytes;
        try {
            CharsetEncoder newEncoder = Charset.forName(contentType.getEncoding()).newEncoder();
            if (!newEncoder.canEncode(txt)) {
                contentType = contentType.tryUTF8();
            }
            bytes = txt.getBytes(contentType.getEncoding());
        } catch (UnsupportedEncodingException e) {
            NanoHTTPD.LOG.log(Level.SEVERE, "encoding problem, responding nothing", e);
            bytes = new byte[0];
        }
        return newFixedLengthResponse(status, contentType.getContentTypeHeader(), new ByteArrayInputStream(bytes), bytes.length);
    }
}
 
开发者ID:VideoDemo,项目名称:M3U8_Video_demo,代码行数:23,代码来源:NanoHTTPD.java

示例7: write

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
/**
 * If the description cannot be encoded using the current encoding change the encoder
 */
public void write(ByteArrayOutputStream tagBuffer) {
    CharsetEncoder encoder = Charset.forName(TextEncoding.CHARSET_ISO_8859_1).newEncoder();
    String origUrl = getUrlLink();
    if (!encoder.canEncode(origUrl)) {
        //ALL W Frames only support ISO-8859-1 for the url itself, if unable to encode let us assume
        //the link just needs url encoding
        setUrlLink(encodeURL(origUrl));

        //We still cant convert so just set log error and set to blank to allow save to continue
        if (!encoder.canEncode(getUrlLink())) {
            logger.warning(ErrorMessage.MP3_UNABLE_TO_ENCODE_URL.getMsg(origUrl));
            setUrlLink("");
        }
        //it was ok, just note the modification made
        else {
            logger.warning(ErrorMessage.MP3_URL_SAVED_ENCODED.getMsg(origUrl, getUrlLink()));
        }
    }
    super.write(tagBuffer);
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:24,代码来源:AbstractFrameBodyUrlLink.java

示例8: validateInput

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
@Override
protected String validateInput() {
    String errorMessage = super.validateInput();
    
    if (errorMessage == null) {
        // #222846 - non-ascii characters in installation path
        File installationFolder = new File(getDestinationPath());
        CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder();
        if (!encoder.canEncode(installationFolder.getAbsolutePath())) {
            return StringUtils.format(panel.getProperty(ERROR_CONTAINS_NON_ASCII_CHARS));
        }
    }
    
    return errorMessage;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:HelloWorldPanel.java

示例9: sanitize

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
private String sanitize(String title) {
    StringBuilder sb = new StringBuilder();
    char[] cs = title.toCharArray();
    CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
    for (char c : cs) {
        if (!valid(c) || !asciiEncoder.canEncode(c)) {
            c = unaccent(c);
        }
        sb.append(c);

    }
    return sb.toString();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:OMapContainer.java

示例10: getAsciiKeycodes

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
private List<Integer> getAsciiKeycodes() {
    CharsetEncoder asciiEncoder = Charset.forName("ascii").newEncoder();
    Set<Entry<Integer, String>> entrySet = keyCodeText.entrySet();
    List<Integer> out = new ArrayList<Integer>();
    for (Entry<Integer, String> entry : entrySet) {
        String keyText = KeyEvent.getKeyText(entry.getKey());
        if (keyText.length() == 1 && asciiEncoder.canEncode(keyText)) {
            out.add(entry.getKey());
        }
    }
    return out;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:Generator.java

示例11: determineConsecutiveBinaryCount

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
/**
 * Determines the number of consecutive characters that are encodable using binary compaction.
 *
 * @param msg      the message
 * @param startpos the start position within the message
 * @param encoding the charset used to convert the message to a byte array
 * @return the requested character count
 */
private static int determineConsecutiveBinaryCount(String msg, int startpos, Charset encoding)
    throws WriterException {
  final CharsetEncoder encoder = encoding.newEncoder();
  int len = msg.length();
  int idx = startpos;
  while (idx < len) {
    char ch = msg.charAt(idx);
    int numericCount = 0;

    while (numericCount < 13 && isDigit(ch)) {
      numericCount++;
      //textCount++;
      int i = idx + numericCount;
      if (i >= len) {
        break;
      }
      ch = msg.charAt(i);
    }
    if (numericCount >= 13) {
      return idx - startpos;
    }
    ch = msg.charAt(idx);

    if (!encoder.canEncode(ch)) {
      throw new WriterException("Non-encodable character detected: " + ch + " (Unicode: " + (int) ch + ')');
    }
    idx++;
  }
  return idx - startpos;
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:39,代码来源:PDF417HighLevelEncoder.java

示例12: isValidForCharset

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
private static boolean isValidForCharset(String id, String charsetName) {
  CharsetEncoder encoder = null;
  try {
    Charset charset = Charset.forName(charsetName);
    encoder = charset.newEncoder();
  } catch (UnsupportedCharsetException e) {
    Log.w("Unsupported charset: " + charsetName);
  }
  if (encoder != null && !encoder.canEncode(id)) {
    Log.v("Invalid id (contains invalid characters): " + id);
    return false;
  }
  return true;
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:15,代码来源:Util.java

示例13: canEncode

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
/**
 * Check if encode can handle the chars in this string.
 *
 */
protected boolean canEncode(String s) {
    final CharsetEncoder encoder =
        Charset.forName(System.getProperty("file.encoding")).newEncoder();
    char[] chars = s.toCharArray();
    for (int i=0; i<chars.length; i++) {
        if(!encoder.canEncode(chars[i])) {
            return false;
        }
    }
    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:IndentingWriter.java

示例14: getAllAvailableChars

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
private String getAllAvailableChars(String charsetName) {
    CharsetEncoder ce = Charset.forName(charsetName).newEncoder();
    StringBuilder result = new StringBuilder();
    for (char c = 0; c < Character.MAX_VALUE; c++) {
        if (ce.canEncode(c)) {
            result.append(c);
        }
    }
    return result.toString();
}
 
开发者ID:justjanne,项目名称:SteamAudio-Java,代码行数:11,代码来源:FontTexture.java

示例15: determineConsecutiveBinaryCount

import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
private static int determineConsecutiveBinaryCount(String msg, int startpos, Charset
        encoding) throws WriterException {
    CharsetEncoder encoder = encoding.newEncoder();
    int len = msg.length();
    int idx = startpos;
    while (idx < len) {
        char ch = msg.charAt(idx);
        int numericCount = 0;
        while (numericCount < 13 && isDigit(ch)) {
            numericCount++;
            int i = idx + numericCount;
            if (i >= len) {
                break;
            }
            ch = msg.charAt(i);
        }
        if (numericCount >= 13) {
            return idx - startpos;
        }
        ch = msg.charAt(idx);
        if (encoder.canEncode(ch)) {
            idx++;
        } else {
            throw new WriterException("Non-encodable character detected: " + ch + " (Unicode:" +
                    " " + ch + ')');
        }
    }
    return idx - startpos;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:30,代码来源:PDF417HighLevelEncoder.java


注:本文中的java.nio.charset.CharsetEncoder.canEncode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。