/* * 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.ByteArrayInputStream; import java.io.File; import org.tranche.hash.BigHash; import org.tranche.get.GetFileTool; import org.tranche.util.IOUtil; import org.tranche.project.file.ProjectFile; import org.tranche.project.file.part.ProjectFilePart; import org.tranche.project.file.ProjectFileUtil; import org.tranche.util.TempFileUtil; /** * This is an example snippet of code that shows the contents of a project file. * * @author Jayson Falkner - jfalkner@umich.edu */ public class ShowProjectFile { 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); gft.setValidate(false); // save the contents to a temporary file File temp = TempFileUtil.createTemporaryFile(); temp.deleteOnExit(); // get the file gft.getFile(temp); // convert the bytes to an object ProjectFile pf = ProjectFileUtil.read(new ByteArrayInputStream(IOUtil.getBytes(temp))); // display the info System.out.println("\n*** Project File Information ***"); System.out.println("Tranche Hash: "+hash); System.out.println("Name: "+pf.getName()); System.out.println("Description: "+pf.getDescription()); System.out.println("Size of files: "+pf.getSize()); System.out.println("Number of files: "+pf.getParts().size()); System.out.println("*** Files in this project (hash/name pairs) ***"); for (ProjectFilePart pfp : pf.getParts()) { System.out.println(pfp.getRelativeName() + ", size: "+pfp.getHash().getLength()); System.out.println(" Tranche Hash: "+pfp.getHash()); } } }