1 /*- 2 * Copyright (C) 2008 Erik Larsson 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package org.catacombae.hfs.types.hfscommon; 19 20 import java.io.PrintStream; 21 import org.catacombae.csjc.PrintableStruct; 22 import org.catacombae.csjc.StructElements; 23 import org.catacombae.csjc.structelements.Dictionary; 24 import org.catacombae.hfs.types.hfsplus.HFSPlusCatalogThread; 25 import org.catacombae.hfs.types.hfs.CdrFThdRec; 26 27 /** 28 * @author <a href="http://www.catacombae.org/" target="_top">Erik Larsson</a> 29 */ 30 public abstract class CommonHFSCatalogFileThread extends CommonHFSCatalogThread 31 implements PrintableStruct, StructElements 32 { length()33 public abstract int length(); getBytes()34 public abstract byte[] getBytes(); 35 36 /* @Override */ print(PrintStream ps, String prefix)37 public void print(PrintStream ps, String prefix) { 38 ps.println(prefix + CommonHFSCatalogFileThread.class.getSimpleName() + ":"); 39 printFields(ps, prefix + " "); 40 } 41 create(HFSPlusCatalogThread data)42 public static CommonHFSCatalogFileThread create(HFSPlusCatalogThread data) { 43 return new HFSPlusImplementation(data); 44 } 45 create(CdrFThdRec data)46 public static CommonHFSCatalogFileThread create(CdrFThdRec data) { 47 return new HFSImplementation(data); 48 } 49 50 private static class HFSPlusImplementation extends CommonHFSCatalogFileThread { 51 private final HFSPlusCatalogThread data; 52 HFSPlusImplementation(HFSPlusCatalogThread data)53 public HFSPlusImplementation(HFSPlusCatalogThread data) { 54 this.data = data; 55 } 56 length()57 public int length() { 58 return data.length(); 59 } 60 61 @Override getParentID()62 public CommonHFSCatalogNodeID getParentID() { 63 return CommonHFSCatalogNodeID.create(data.getParentID()); 64 } 65 66 @Override getNodeName()67 public CommonHFSCatalogString getNodeName() { 68 return CommonHFSCatalogString.createHFSPlus(data.getNodeName()); 69 } 70 71 @Override getBytes()72 public byte[] getBytes() { 73 return data.getBytes(); 74 } 75 printFields(PrintStream ps, String prefix)76 public void printFields(PrintStream ps, String prefix) { 77 ps.println(prefix + "data:"); 78 data.print(ps, prefix + " "); 79 } 80 81 /* @Override */ getStructElements()82 public Dictionary getStructElements() { 83 return data.getStructElements(); 84 } 85 } 86 87 private static class HFSImplementation extends CommonHFSCatalogFileThread { 88 private final CdrFThdRec data; 89 HFSImplementation(CdrFThdRec data)90 public HFSImplementation(CdrFThdRec data) { 91 this.data = data; 92 } 93 length()94 public int length() { 95 return data.length(); 96 } 97 98 @Override getParentID()99 public CommonHFSCatalogNodeID getParentID() { 100 return CommonHFSCatalogNodeID.create(data.getFthdParID()); 101 } 102 103 @Override getNodeName()104 public CommonHFSCatalogString getNodeName() { 105 return CommonHFSCatalogString.createHFS(data.getFthdCName()); 106 } 107 108 @Override getBytes()109 public byte[] getBytes() { 110 return data.getBytes(); 111 } 112 printFields(PrintStream ps, String prefix)113 public void printFields(PrintStream ps, String prefix) { 114 ps.println(prefix + "data:"); 115 data.print(ps, prefix + " "); 116 } 117 118 /* @Override */ getStructElements()119 public Dictionary getStructElements() { 120 return data.getStructElements(); 121 } 122 } 123 } 124