1 /*- 2 * Copyright (C) 2006 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.carbon; 19 20 import org.catacombae.csjc.structelements.Dictionary; 21 import org.catacombae.util.Util; 22 import java.io.PrintStream; 23 import org.catacombae.csjc.PrintableStruct; 24 import org.catacombae.csjc.StructElements; 25 26 public class FourCharCode implements PrintableStruct, StructElements { 27 /* 28 * struct FourCharCode 29 * size: 4 bytes 30 * description: a typedef originally 31 * 32 * BP Size Type Identifier Description 33 * ------------------------------------------- 34 * 0 4 UInt32 fourCharCode 35 */ 36 37 private final byte[] fourCharCode = new byte[4]; 38 FourCharCode(byte[] data, int offset)39 public FourCharCode(byte[] data, int offset) { 40 System.arraycopy(data, offset + 0, fourCharCode, 0, 4); 41 } 42 getFourCharCode()43 public int getFourCharCode() { 44 return Util.readIntBE(fourCharCode); 45 } 46 getFourCharCodeAsString()47 public String getFourCharCodeAsString() { 48 return Util.toASCIIString(getFourCharCode()); 49 } 50 printFields(PrintStream ps, String prefix)51 public void printFields(PrintStream ps, String prefix) { 52 ps.println(prefix + " fourCharCode: \"" + getFourCharCodeAsString() + "\""); 53 } 54 print(PrintStream ps, String prefix)55 public void print(PrintStream ps, String prefix) { 56 ps.println(prefix + "FourCharCode:"); 57 printFields(ps, prefix); 58 } 59 getBytes()60 public byte[] getBytes() { 61 return Util.createCopy(fourCharCode); 62 } 63 64 /* @Override */ getStructElements()65 public Dictionary getStructElements() { 66 DictionaryBuilder db = new DictionaryBuilder(FourCharCode.class.getSimpleName()); 67 68 db.addEncodedString("fourCharCode", fourCharCode, "US-ASCII"); 69 70 return db.getResult(); 71 } 72 } 73