/* * 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 org.tranche.Signature; import org.tranche.hash.BigHash; import org.tranche.util.FileEncoding; import org.tranche.get.GetFileTool; import org.tranche.meta.MetaData; import org.tranche.meta.MetaDataAnnotation; /** * This is an example snippet of code that shows the contents of a project file. * * @author Jayson Falkner - jfalkner@umich.edu */ public class ShowMetaData { 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); // get the meta-data MetaData md = gft.getMetaData(); // dump the info System.out.println("*** Meta-data File Contents ***"); System.out.println("Version: "+md.getVersion()); System.out.println("Arbitrary File Name: "+md.getName()); System.out.println("Suggested MIME Type: "+md.getMimeType()); System.out.println("Suggested Data Expiration: "+md.getExpiration()); System.out.println("Last-Updated Timestamp: "+md.getTimestamp()); System.out.println("\n*** Encodings ***"); for (FileEncoding fe : md.getEncodings()) { System.out.println(" "+fe.getName()+", hash: "+fe.getHash()); } System.out.println("\n*** Signatures ***"); for (Signature sig : md.getSignatures()) { System.out.println(" "+sig.getCert().getSubjectDN().getName()+", algorithm: "+sig.getAlgorithm()); } System.out.println("\n*** 1MB File Segments (in order) ***"); for (BigHash part : md.getParts()) { System.out.println(" "+part+", size: "+part.getLength()); } System.out.println("\n*** Known Annotations ***"); for (MetaDataAnnotation mda : md.getAnnotations()) { System.out.println(" "+mda.getName()+": "+mda.getValue()); } } }