如何防止诺曼底下载重复文件

时间:2016-06-27 06:16:00

标签: java xml file http download

使用以下xml将请求发送到服务器以供下载

<?xml version="1.0" encoding="UTF-8"?>
<ResourceSet xmlns:v01"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <cycleTime>123</cycleTime>
    <object>
        <sourceUrl>http://10.34894.494/23.png</sourceUrl>
         <accessUrl>http://10.126.45.72/cme/23.png</accessUrl>
        <objectMetadata>
            <headerName>Content-Length</headerName>
            <headerName>E-Tag</headerName>
        </objectMetadata>
    </object> 
    <object>
        <sourceUrl>http://10.84375.72/cme/23.png</sourceUrl>
         <accessUrl>http://10.4575.572/cme/logo/23.png</accessUrl>
        <objectMetadata>
            <headerName>Content-Length</headerName>
            <headerName>E-Tag</headerName>
        </objectMetadata>
    </object> 
</ResourceSet>

有2个对象,它们具有相同的源URL和不同的Access URl。 我的工作是只下载一次图像,因为源URL是重复的。

迭代对象,但我怎么知道两个对象有相同的源URL可供下载?

有2个对象,它们具有相同的源URL和不同的Access URl。 我的工作是只下载一次图像,因为源URL是重复的。

迭代对象,但我怎么知道两个对象有相同的源URL可供下载?

public void download_resourceset_object_urls_images_to_local() throws Throwable {
    List<String> sourceURis = GFDUtils.getSourceOrAccessURLs(xmlPath + xmlFileName, "sourceUrl");
    dwInfoList = new HashMap<String, DownloadFileInfo>();
    NSAUtils.removeFiles(ConfigLoader.DOWNLOAD_DIR);
    boolean flag = HTTPClientFileDownload.downloadFile(sourceURis, ConfigLoader.DOWNLOAD_DIR, dwInfoList);
    if (flag == true) {
        logger.info("All URL files / images are downloaded successfully....");
    } else
        throw new GenericException("Files are not available / Failed download ");
}

这里正在迭代Xml并获取源URL以供下载

public static List<String> getSourceOrAccessURLs(String xmlPath, String urlname) throws IOException {
        XStream xs = new XStream();
        boolean flag = XMLValidation.validateXMLSchema(xmlPath);
        File file = new File(xmlPath);
        String xml = FileUtils.readFileToString(file);
        if (flag == true) {
            List<String> urls = new ArrayList<>();
            try {
                xs.processAnnotations(Resourceset.class);
                Resourceset rs = (Resourceset) xs.fromXML(xml);
                List<ResourcesetObject> rsoOject = rs.getResourcesetObject();
                for (ResourcesetObject resourcesetObject : rsoOject) {

                    if (urlname.equals("sourceUrl")) {

                        urls.add(resourcesetObject.getSourceUrl());

                    } else {
                        urls.add(resourcesetObject.getAccessUrl());
                    }

                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            return urls;
        }

        return null;
    }

此网址传递下载。

请帮忙

谢谢,

0 个答案:

没有答案