 |
|
|  |
À¥¿¡¼ ÆÄÀÏ »çÀÌÁî¿Í ÄÜÅÙÆ®(ÄÁÅÙÃ÷) ŸÀÔ ¾Ë¾Æº¸´Â »ùÇÃÄÚµå |
|
|
 |
8³â Àü |
À¥¿¡¼ ÆÄÀÏ »çÀÌÁî¿Í ÄÜÅÙÆ®(ÄÁÅÙÃ÷) ŸÀÔ ¾Ë¾Æº¸´Â »ùÇÃÄÚµå
Sample Code for checking file size and content type.
private long fileSize = 0;
private String contentType = "";
private void checkFileSizeAndType(final String openUrl){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
URL mUrl;
try {
mUrl = new URL(openUrl);
final URLConnection connection = mUrl.openConnection();
connection.setConnectTimeout(8000);
connection.setReadTimeout(8000);
connection.connect();
String content_length = connection.getHeaderField("Content-Length");
contentType = connection.getHeaderField("Content-Type");
if(content_length == null){
fileSize = -1;
}else{
fileSize = Long.parseLong(content_length);
}
} catch (SSLException e) {
fileSize = -2;
} catch (NullPointerException e) {
fileSize = -1;
e.printStackTrace();
} catch (MalformedURLException e) {
fileSize = -1;
e.printStackTrace();
} catch (IOException e) {
fileSize = -1;
e.printStackTrace();
}
if(fileSize == -2){
TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {return null;}
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
}
};
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
}
try {
mUrl = new URL(openUrl);
final URLConnection connection = mUrl.openConnection();
connection.setConnectTimeout(8000);
connection.setReadTimeout(8000);
connection.connect();
String content_length = connection.getHeaderField("Content-Length");
if(content_length == null){
fileSize = -1;
}else{
fileSize = Long.parseLong(content_length);
}
} catch (NullPointerException e) {
fileSize = -1;
e.printStackTrace();
} catch (MalformedURLException e) {
fileSize = -1;
e.printStackTrace();
} catch (IOException e) {
fileSize = -1;
e.printStackTrace();
}
}//SSL
APLog.d(TAG, CLASS, "fileSize " + fileSize + " /contentType " + contentType);
getMainHandler().post(new APRunnable() {
@Override
protected void runs() {
if(fileSize > 0 && isVideoContentType(contentType)) {
afterFileSizeAndType(true);
}
else {
afterFileSizeAndType(false);
}
}
});
}
});
thread.setDaemon(true);
thread.start();
}
private boolean isVideoContentType(String type) {
if(type.contains("/")) {
if(type.equalsIgnoreCase("application/x-mpegURL")
|| type.equalsIgnoreCase("application/vnd.apple.mpegurl")) return true;
String[] t = type.split("/");
if(t.length > 1) {
if(t[0].equalsIgnoreCase("video")) {
return true;
}
}
}
return false;
}
|
|
̵̧ : 301 |
̵̧
¸ñ·Ï
|
|
|  |
|