/* Copyright (c) 2007 Joseph Gleason Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Current versions of this and other code can be downloaded at: http://gleason.cc/ */ package cc.glsn.v15.argus; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.ResultSet; import java.util.Scanner; import java.util.TreeSet; class ImageData { private ImageID id; private String md5; private long size; private TreeSet drives; private TreeSet paritySets; public ImageData(ResultSet r) throws java.sql.SQLException { id=new ImageID(r.getString("name")); md5=r.getString("md5"); size=r.getLong("size"); initDataStructs(); } public ImageData(File f) throws FileNotFoundException, IOException { id=new ImageID(f.getName()); Scanner scan=new Scanner(new FileInputStream("/argus/md5/" + id.getID() +".md5")); md5=scan.next(); scan.close(); size=f.length(); initDataStructs(); } private void initDataStructs() { drives=new TreeSet(); paritySets=new TreeSet(); } public ImageID getID() { return id; } public String getMd5() { return md5; } public long getSize() { return size; } public void addDrive(DriveID did) { drives.add(did); } public void addParitySet(ParitySetID psID) { paritySets.add(psID); } public int getParityCount() { return paritySets.size(); } public TreeSet getDrives() { return new TreeSet(drives); } public TreeSet getParitySet() { return new TreeSet(paritySets); } public String getStatus() { StringBuilder sb=new StringBuilder(); sb.append(id.getID()); sb.append(":"); sb.append(" drives:"); sb.append(drives.size()); sb.append(" psets:"); sb.append(paritySets.size()); return sb.toString(); } }