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


Java EncodingMap类代码示例

本文整理汇总了Java中org.apache.xerces.util.EncodingMap的典型用法代码示例。如果您正苦于以下问题:Java EncodingMap类的具体用法?Java EncodingMap怎么用?Java EncodingMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getJavaEncoding

import org.apache.xerces.util.EncodingMap; //导入依赖的package包/类
public String getJavaEncoding() {
    String javaEncoding = null;
    String mimeEncoding = getMimeEncoding();

    if (mimeEncoding != null) {
        if (mimeEncoding.equals( "DEFAULT" ))
            javaEncoding =  "UTF8";
        else if (mimeEncoding.equalsIgnoreCase( "UTF-16" ))
            javaEncoding = "Unicode";
        else
            javaEncoding = EncodingMap.getIANA2JavaMapping( mimeEncoding );    
    } 
    if(javaEncoding == null)   // Should never return null
        javaEncoding = "UTF8";
    return(javaEncoding);
}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:17,代码来源:DOMParserSaveEncoding.java

示例2: getWriter

import org.apache.xerces.util.EncodingMap; //导入依赖的package包/类
/**
 * Returns a writer for this encoding based on
 * an output stream.
 *
 * @return A suitable writer
 * @exception UnsupportedEncodingException There is no convertor
 *  to support this encoding
 */
public Writer getWriter(OutputStream output)
    throws UnsupportedEncodingException {
    // this should always be true!
    if (javaName != null) 
        return new OutputStreamWriter(output, javaName);
    javaName = EncodingMap.getIANA2JavaMapping(ianaName);
    if(javaName == null) 
        // use UTF-8 as preferred encoding
        return new OutputStreamWriter(output, "UTF8");
    return new OutputStreamWriter(output, javaName);
}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:20,代码来源:EncodingInfo.java

示例3: writeHeader

import org.apache.xerces.util.EncodingMap; //导入依赖的package包/类
/**
 * Writes the XML Declaration and the opening RDF tag to the print Writer.
 * Encoding attribute is specified as the encoding argument.
 *
 * @param out PrintWriter
 * @throws IOException
 */
protected void writeHeader(OutputStreamWriter out) throws IOException {

  //validate
  if (out != null) {

    //wrapper for output stream writer (enable autoflushing)
    PrintWriter writer = new PrintWriter(out, true);

    //get encoding from the Encoding map
    String encoding = EncodingMap.getJava2IANAMapping(out.getEncoding());

    //only insert encoding if there is a value
    if (encoding != null) {

      //print opening tags <?xml version="1.0" encoding=*encoding*?>
      writer.println("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>");
    }
    else {

      //print opening tags <?xml version="1.0"?>
      writer.println("<?xml version=\"1.0\"?>");
    }

    //print the Entities
    this.writeXMLEntities(writer);

    //print the opening RDF tag (including namespaces)
    this.writeRDFHeader(writer);
  }
  else {

    throw new IllegalArgumentException("Cannot write to null Writer.");
  }
}
 
开发者ID:quoll,项目名称:mulgara,代码行数:42,代码来源:GraphXMLWriter.java

示例4: EncodingInfo

import org.apache.xerces.util.EncodingMap; //导入依赖的package包/类
/**
 * Creates new <code>EncodingInfo</code> instance.
 */
public EncodingInfo(String ianaName, String javaName, int lastPrintable) {
    this.ianaName = ianaName;
    this.javaName = EncodingMap.getIANA2JavaMapping(ianaName);
    this.lastPrintable = lastPrintable;
}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:9,代码来源:EncodingInfo.java

示例5: setInputSource

import org.apache.xerces.util.EncodingMap; //导入依赖的package包/类
/** Sets the input source. */
public void setInputSource(XMLInputSource source) throws IOException {

    // reset state
    fElementCount = 0;
    fElementDepth = -1;
    fByteStream = null;
    fCurrentEntityStack.removeAllElements();

    fBeginLineNumber = 1;
    fBeginColumnNumber = 1;
    fBeginCharacterOffset = 0;
    fEndLineNumber = fBeginLineNumber;
    fEndColumnNumber = fBeginColumnNumber;
    fEndCharacterOffset = fBeginCharacterOffset;

    // reset encoding information
    fIANAEncoding = fDefaultIANAEncoding;
    fJavaEncoding = fIANAEncoding;

    // get location information
    String encoding = source.getEncoding();
    String publicId = source.getPublicId();
    String baseSystemId = source.getBaseSystemId();
    String literalSystemId = source.getSystemId();
    String expandedSystemId = expandSystemId(literalSystemId, baseSystemId);

    // open stream
    Reader reader = source.getCharacterStream();
    if (reader == null) {
        InputStream inputStream = source.getByteStream();
        if (inputStream == null) {
            URL url = new URL(expandedSystemId);
            inputStream = url.openStream();
        }
        fByteStream = new PlaybackInputStream(inputStream);
        String[] encodings = new String[2];
        if (encoding == null) {
            fByteStream.detectEncoding(encodings);
        }
        else {
            encodings[0] = encoding;
        }
        if (encodings[0] == null) {
            encodings[0] = fDefaultIANAEncoding;
            if (fReportErrors) {
                fErrorReporter.reportWarning("HTML1000", null);
            }
        }
        if (encodings[1] == null) {
            encodings[1] = EncodingMap.getIANA2JavaMapping(encodings[0].toUpperCase());
            if (encodings[1] == null) {
                encodings[1] = encodings[0];
                if (fReportErrors) {
                    fErrorReporter.reportWarning("HTML1001", new Object[]{encodings[0]});
                }
            }
        }
        fIANAEncoding = encodings[0];
        fJavaEncoding = encodings[1];
        /* PATCH: Asgeir Asgeirsson */
        fIso8859Encoding = fIANAEncoding == null 
                        || fIANAEncoding.toUpperCase().startsWith("ISO-8859")
                        || fIANAEncoding.equalsIgnoreCase(fDefaultIANAEncoding);
        encoding = fIANAEncoding;
        reader = new InputStreamReader(fByteStream, fJavaEncoding);
    }
    fCurrentEntity = new CurrentEntity(reader, encoding,
                                       publicId, baseSystemId,
                                       literalSystemId, expandedSystemId);

    // set scanner and state
    setScanner(fContentScanner);
    setScannerState(STATE_START_DOCUMENT);

}
 
开发者ID:ecologylab,项目名称:BigSemanticsJava,代码行数:77,代码来源:HTMLScanner.java

示例6: changeEncoding

import org.apache.xerces.util.EncodingMap; //导入依赖的package包/类
/**
       * Tries to change the encoding used to read the input stream to the specified one
       * @param charset the charset that should be used
       * @return <code>true</code> when the encoding has been changed
       */
private boolean changeEncoding(String charset) {
	if (charset == null || fByteStream == null) {
		return false;
	}
	charset = charset.trim();
	boolean encodingChanged = false;
	try {
	    String ianaEncoding = charset;
	    String javaEncoding = EncodingMap.getIANA2JavaMapping(ianaEncoding.toUpperCase());
	    if (DEBUG_CHARSET) {
	        System.out.println("+++ ianaEncoding: "+ianaEncoding);
	        System.out.println("+++ javaEncoding: "+javaEncoding);
	    }
	    if (javaEncoding == null) {
	        javaEncoding = ianaEncoding;
	        if (fReportErrors) {
	            fErrorReporter.reportError("HTML1001", new Object[]{ianaEncoding});
	        }
	    }
	    // patch: Marc Guillemot
	    if (!javaEncoding.equals(fJavaEncoding)) { 
	      	if (!isEncodingCompatible(javaEncoding, fJavaEncoding)) {
	            if (fReportErrors) {
	                fErrorReporter.reportError("HTML1015", new Object[]{javaEncoding,fJavaEncoding});
	            }
	     	}
	  		// change the charset
	     	else {
	            fIso8859Encoding = ianaEncoding == null 
	                    || ianaEncoding.toUpperCase().startsWith("ISO-8859")
	                    || ianaEncoding.equalsIgnoreCase(fDefaultIANAEncoding);
	            fJavaEncoding = javaEncoding;
	            fCurrentEntity.setStream(new InputStreamReader(fByteStream, javaEncoding));
	            fByteStream.playback();
	            fElementDepth = fElementCount;
	            fElementCount = 0;
                   encodingChanged = true;
	     	}
	     }
	}
	catch (UnsupportedEncodingException e) {
	    if (fReportErrors) {
	        fErrorReporter.reportError("HTML1010", new Object[]{charset});
	    }
	    // NOTE: If the encoding change doesn't work, 
	    //       then there's no point in continuing to 
	    //       buffer the input stream.
	    fByteStream.clear();
	    fByteStream = null;
	}
	return encodingChanged;
}
 
开发者ID:ecologylab,项目名称:BigSemanticsJava,代码行数:58,代码来源:HTMLScanner.java


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