當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。