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


Java URLConnection.getContentEncoding方法代码示例

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


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

示例1: initialiseResponse

import java.net.URLConnection; //导入方法依赖的package包/类
/**
 * Initialise response
 * 
 * @param urlConnection  url connection
 */
protected void initialiseResponse(URLConnection urlConnection)
{
    String type = urlConnection.getContentType();
    if (type != null)
    {
        int encodingIdx = type.lastIndexOf("charset=");
        if (encodingIdx == -1)
        {
            String encoding = urlConnection.getContentEncoding();
            if (encoding != null && encoding.length() > 0)
            {
                type += ";charset=" + encoding;
            }
        }
        
        response.setContentType(type);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:24,代码来源:HTTPProxy.java

示例2: getInputStream

import java.net.URLConnection; //导入方法依赖的package包/类
private static TrackingInputStream getInputStream(URLConnection conn) throws IOException {
    String encoding = conn.getContentEncoding();
    if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
        return new TrackingGZIPInputStream(new ExposedGZIPInputStream(conn.getInputStream()));
    }
    return new SimpleTrackingInputStream(conn.getInputStream());
}
 
开发者ID:natjs,项目名称:nat-network-transfer,代码行数:8,代码来源:TransferModule.java

示例3: makeData

import java.net.URLConnection; //导入方法依赖的package包/类
@Override
protected Data makeData () throws Exception
{
    final URLConnection connection = this.url.openConnection ();
    connection.connect ();

    final int len = connection.getContentLength ();

    final ByteArrayOutputStream bos = new ByteArrayOutputStream ( len > 0 ? len : 0 );

    final byte[] buffer = new byte[4096];
    try ( InputStream stream = connection.getInputStream () )
    {
        int rc;
        while ( ( rc = stream.read ( buffer ) ) > 0 )
        {
            bos.write ( buffer, 0, rc );
        }
        bos.close ();
    }

    final String encoding = connection.getContentEncoding ();
    final String type = connection.getContentType ();

    logger.debug ( "Content-Encoding: {}", encoding );
    logger.debug ( "Content-Type: {}", type );

    Charset charset = null;

    if ( this.charset != null )
    {
        charset = this.charset;
    }
    else if ( this.probeCharset )
    {
        charset = makeCharsetFromType ( type );
    }

    return new UrlConnectionData ( convert ( buffer, charset ), null );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:41,代码来源:UrlConnectionInput.java

示例4: getInputStream

import java.net.URLConnection; //导入方法依赖的package包/类
private static TrackingInputStream getInputStream(URLConnection conn) throws IOException {
    String encoding = conn.getContentEncoding();
    if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
      return new TrackingGZIPInputStream(new ExposedGZIPInputStream(conn.getInputStream()));
    }
    return new SimpleTrackingInputStream(conn.getInputStream());
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:8,代码来源:FileTransfer.java

示例5: getWebsiteReader

import java.net.URLConnection; //导入方法依赖的package包/类
public static BufferedReader getWebsiteReader(String link) throws IOException {
    URLConnection conn = new URL(link).openConnection();
    conn.setRequestProperty("User-Agent", "Mozilla");
    String encoding = conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding();
    return new BufferedReader(new InputStreamReader(conn.getInputStream(), encoding));
}
 
开发者ID:Baizey,项目名称:Helpers,代码行数:7,代码来源:TextReader.java

示例6: readFromConnection

import java.net.URLConnection; //导入方法依赖的package包/类
private static String readFromConnection(URLConnection connection) throws IOException {
    InputStream stream;
    if (connection instanceof HttpURLConnection) {
        HttpURLConnection httpConnection = (HttpURLConnection) connection;
        try {
            stream = connection.getInputStream();
        } catch (Exception e) {
            stream = httpConnection.getErrorStream();
        }
    } else {
        stream = connection.getInputStream();
    }
    try {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        while (true) {
            int read = stream.read(buffer);
            if (read == -1) {
                break;
            }
            output.write(buffer, 0, read);
        }
        String charset = connection.getContentEncoding();
        if (charset == null) {
            for (String part : connection.getContentType().split(";")) {
                String part2 = part2.trim();
                if (part2.startsWith("charset=")) {
                    charset = part2.substring("charset=".length());
                    break;
                }
            }
            if (charset == null) {
                charset = "UTF-8";
            }
        }
        String str = new String(output.toByteArray(), charset);
        return str;
    } finally {
        stream.close();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:42,代码来源:WebViewAppLinkResolver.java


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