0

Java アプリケーションの機能を終了するには、助けが必要です。

この関数は、ダウンロード ベース URL のルートにある xml ファイルにリストされているファイルをダウンロードするために使用されます。ファイルの etag をダウンロード済みのファイルの etag と比較し、更新します。しかし、古いファイルがローカル フォルダーに残っているため、競合の問題が発生します。

コードは次のとおりです。

    private Set<Downloadable> getInternetFiles(Proxy proxy, File baseDirectory) {
    Set<Downloadable> result = new HashSet<Downloadable>();
    try
    {
        URL resourceUrl = new URL(UrlClass.DOWNLOAD_URL);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(resourceUrl.openStream());
        NodeList nodeLst = doc.getElementsByTagName("Contents");

        long start = System.nanoTime();
        for (int i = 0; i < nodeLst.getLength(); i++) {
            Node node = nodeLst.item(i);

            if (node.getNodeType() == 1) {
                Element element = (Element)node;
                String key = element.getElementsByTagName("Key").item(0).getChildNodes().item(0).getNodeValue();
                String etag = element.getElementsByTagName("ETag") != null ? element.getElementsByTagName("ETag").item(0).getChildNodes().item(0).getNodeValue() : "-";
                long size = Long.parseLong(element.getElementsByTagName("Size").item(0).getChildNodes().item(0).getNodeValue());

                if (size > 0L) {
                    File file = new File(baseDirectory, "/" + key);
                    if (etag.length() > 1) {
                        etag = Downloadable.getEtag(etag);
                        if ((file.isFile()) && (file.length() == size)) {
                            String localMd5 = Downloadable.getMD5(file);
                            if (localMd5.equals(etag)) continue;
                        }
                    }
                    Downloadable downloadable = new Downloadable(proxy, new URL(UrlClass.DOWNLOAD_URL + key), file, false);
                    downloadable.setExpectedSize(size);
                    result.add(downloadable);
                }
            }
        }
        long end = System.nanoTime();
        long delta = end - start;
        Launcher.getInstance().println("Time to compare : " + delta / 1000000L + " ms ");
    } catch (Exception ex) {
        Launcher.getInstance().println("Couldn't download files", ex);
    }

    return result;
}

プロジェクトを継続するために本当に必要ですが、delete メソッドを実装する方法がわかりません。ありがとう。

4

0 に答える 0