1 17 package com.sun.syndication.fetcher.impl; 18 19 import java.net.URLConnection ; 20 import java.util.regex.Matcher ; 21 import java.util.regex.Pattern ; 22 23 27 public class ResponseHandler { 28 public static final String defaultCharacterEncoding = "ISO-8859-1"; 29 30 private static Pattern characterEncodingPattern = Pattern.compile("charset=([.[^; ]]*)"); 31 32 public static String getCharacterEncoding(URLConnection connection) { 33 return getCharacterEncoding(connection.getContentType()); 34 } 35 36 44 public static String getCharacterEncoding(String contentTypeHeader) { 45 if (contentTypeHeader == null) { 46 return defaultCharacterEncoding; 47 } 48 49 Matcher m = characterEncodingPattern.matcher(contentTypeHeader); 50 if (!m.find()) { 52 return defaultCharacterEncoding; 53 } else { 54 return m.group(1); 55 } 56 } 57 } 58 | Popular Tags |