2009-04-28 10 views
0

urlclassloaderによって動的にロードされるファイルサイズを見つける良い方法はありますか?urlclassloaderによってロードされたjarファイルのサイズを取得します。

私は次のようにurlclassloaderを使用していますが、使用されている帯域幅を追跡する必要があります。

URLClassLoader sysloader = (URLClassLoader) ClassLoader 
      .getSystemClassLoader(); 
Class<URLClassLoader> sysclass = URLClassLoader.class; 
Method method = sysclass.getDeclaredMethod("addURL", parameters); 
method.setAccessible(true); 
method.invoke(sysloader, (Object[]) urls); 

ありがとうございます!

答えて

0

あなたがロードされているURLを知っている場合、HTTP URLです、そしてあなたは、彼らが戻って上のContent-Lengthヘッダいるサーバーを確保することができ、あなたは次のように自分のサイズを取得することができます

public static int getContentLength (URL url) 
    throws IOException 
{ 
    String contentLength = url.openConnection().getHeaderField("Content-Length"); 
    if (contentLength == null) { 
     throw new IllegalArgumentException(url + " didn't have a " 
      + "Content-Length header"); 
    } else { 
     return Integer.parseInt(contentLength); 
    } 
} 
関連する問題