/** * @param sourceFile File to read from * @return List of String objects with the shas */ public static FileRequestFileContent readRequestFile(final File sourceFile) { if (!sourceFile.isFile() || !(sourceFile.length() > 0)) { return null; } Document d = null; try { d = XMLTools.parseXmlFile(sourceFile.getPath()); } catch (final Throwable t) { logger.log(Level.SEVERE, "Exception in readRequestFile, during XML parsing", t); return null; } if (d == null) { logger.log(Level.SEVERE, "Could'nt parse the request file"); return null; } final Element rootNode = d.getDocumentElement(); if (rootNode.getTagName().equals(TAG_FrostFileRequestFile) == false) { logger.severe( "Error: xml request file does not contain the root tag '" + TAG_FrostFileRequestFile + "'"); return null; } final String timeStampStr = XMLTools.getChildElementsTextValue(rootNode, TAG_timestamp); if (timeStampStr == null) { logger.severe("Error: xml file does not contain the tag '" + TAG_timestamp + "'"); return null; } final long timestamp = Long.parseLong(timeStampStr); final List<Element> nodelist = XMLTools.getChildElementsByTagName(rootNode, TAG_shaList); if (nodelist.size() != 1) { logger.severe("Error: xml request files must contain only one element '" + TAG_shaList + "'"); return null; } final Element rootShaNode = nodelist.get(0); final List<String> shaList = new LinkedList<String>(); final List<Element> xmlKeys = XMLTools.getChildElementsByTagName(rootShaNode, TAG_sha); for (final Element el : xmlKeys) { final Text txtname = (Text) el.getFirstChild(); if (txtname == null) { continue; } final String sha = txtname.getData(); shaList.add(sha); } final FileRequestFileContent content = new FileRequestFileContent(timestamp, shaList); return content; }
public static void main(final String[] args) { final File targetFile = new File("D:\\abc.def"); final File tmp = new File(targetFile.getPath() + ".frftmp"); if (!FileAccess.compressFileGZip(targetFile, tmp)) { return; // error } targetFile.delete(); tmp.renameTo(targetFile); }
/** * Enqueue a direct GET if not already enqueued, or already downloaded to download dir. * * @return true if item was enqueued */ public boolean maybeEnqueueDirectGet( final FrostDownloadItem dlItem, final long expectedFileSize) { if (!isDirectTransferInProgress(dlItem)) { final File targetFile = new File(dlItem.getDownloadFilename()); if (!targetFile.isFile() || targetFile.length() != expectedFileSize) { directTransferQueue.appendItemToQueue(dlItem); return true; } } return false; }