use of net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo in project processdash by dtuma.
the class ResourceBridgeClient method getDiff.
private ResourceCollectionDiff getDiff() throws IOException {
// start by initiating the HTTP connection to the server
URLConnection conn = makeGetRequest(LIST_ACTION);
conn.connect();
// now, while the server is thinking, do our calculations locally.
localCollection.validate();
ResourceCollectionInfo localList = new ResourceListing(localCollection, ResourceFilterFactory.DEFAULT_FILTER);
// finally, retrieve the list from the server and compare the two.
serverVersion = conn.getHeaderField(VERSION_HEADER);
ResourceCollectionInfo remoteList = XmlCollectionListing.parseListing(new BufferedInputStream(conn.getInputStream()));
return new ResourceCollectionDiff(localList, remoteList);
}
use of net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo in project processdash by dtuma.
the class ResourceBridgeClient method uploadSingleFile.
/**
* Save a single file to the server.
*
* @param remoteUrl the url of the team server
* @param resourceName the name of the resource to save the data as
* @param data the data to save to the server
* @return the checksum of the file, as written to the server
* @throws IOException if an IO error occurs
* @throws LockFailureException if the team server rejects the request
* because a lock is required.
*/
public static Long uploadSingleFile(URL remoteUrl, String resourceName, InputStream data) throws IOException, LockFailureException {
byte[] response = doAnonymousPostRequest(remoteUrl, UPLOAD_ACTION, resourceName, data);
ResourceCollectionInfo remoteList = XmlCollectionListing.parseListing(new ByteArrayInputStream(response));
return remoteList.getChecksum(resourceName);
}
use of net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo in project processdash by dtuma.
the class BridgedWorkingDirectory method syncTimestampIsRecent.
private boolean syncTimestampIsRecent() {
try {
String timestamp = getMetadata(SYNC_TIMESTAMP);
if (timestamp == null)
return false;
ResourceFilter filter = ResourceFilterFactory.getForRequest(Collections.singletonMap(ResourceFilterFactory.LAST_MOD_PARAM, timestamp));
ResourceCollectionInfo changedFiles = new ResourceListing(client.localCollection, filter);
return changedFiles.listResourceNames().isEmpty();
} catch (Exception e) {
return false;
}
}
use of net.sourceforge.processdash.tool.bridge.ResourceCollectionInfo in project processdash by dtuma.
the class ResourceBridgeClient method downloadFiles.
private ResourceCollectionInfo downloadFiles(URLConnection conn) throws IOException {
ResourceCollectionInfo info = null;
InputStream response = new BufferedInputStream(conn.getInputStream());
ZipInputStream zipIn = new ZipInputStream(response);
ZipEntry e;
while ((e = zipIn.getNextEntry()) != null) {
String name = e.getName();
long modTime = e.getTime();
if (ResourceContentStream.MANIFEST_FILENAME.equals(name)) {
InputStream infoIn = new ByteArrayInputStream(FileUtils.slurpContents(zipIn, false));
info = XmlCollectionListing.parseListing(infoIn);
continue;
}
OutputStream out = localCollection.getOutputStream(name, modTime);
if (out == null)
// a member of our collection. Discard it.
continue;
logger.fine("downloading resource " + name);
FileUtils.copyFile(zipIn, out);
out.close();
zipIn.closeEntry();
}
zipIn.close();
return info;
}
Aggregations