/* * Copyright 2005-2007 The Regents of the University of Michigan * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.tranche.example; import java.io.File; import org.tranche.hash.BigHash; import org.tranche.get.CommandLineGetFileToolListener; import org.tranche.get.GetFileTool; /** * This is an example snippet of code that downloads the contents of a project file. * * @author Jayson Falkner - jfalkner@umich.edu */ public class DownloadProject { public static void main(String[] args) throws Exception { // the hash to download BigHash hash = BigHash.createHashFromString("mGNNW+dCIIk0hEqUFOgM4QBi15TYjGX3I1I6V7uo9JDKHJu8Ks8kx+hwKhumqFu6XXjCy1D7IqP3/hZjLnqW0MbR2YsAAAAAABdZew=="); // use the GetFileTool to download the project file GetFileTool gft = new GetFileTool(); gft.setHash(hash); // don't bother double-checking digital signatures gft.setValidate(false); // save the contents to a directory -- a file would download just the project file itself File dir = new File("download"); dir.mkdirs(); // before downloading register a command-line display gft.getListeners().add(new CommandLineGetFileToolListener(System.out)); // get the project using the specified base directory gft.getDirectory(dir); } }