Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package resbots.tagfile;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.UUID;
- import resbots.tagfile.tag.Tag;
- import resbots.tagfile.tag.TagByte;
- import resbots.tagfile.tag.TagDouble;
- import resbots.tagfile.tag.TagInteger;
- import resbots.tagfile.tag.TagLong;
- import resbots.tagfile.tag.TagShort;
- public class TaggedFile {
- private UUID uUID;
- private File file;
- private ArrayList<Tag> tags;
- public TaggedFile(File file) {
- this.uUID = UUID.randomUUID();
- this.file = file;
- this.tags = new ArrayList<Tag>();
- }
- public void save() throws IOException {
- DataOutputStream dOS = new DataOutputStream(new FileOutputStream(file));
- for (Tag tag : tags) {
- dOS.writeByte(tag.getTagID());
- tag.save(dOS);
- }
- dOS.writeByte(Tag.TAG_END);
- dOS.flush();
- dOS.close();
- }
- public void load() throws IOException {
- DataInputStream dIS = new DataInputStream(new FileInputStream(file));
- byte tagID = dIS.readByte();
- while (tagID != Tag.TAG_END) {
- Tag newTag = null;
- switch (tagID) {
- case Tag.TAG_BYTE:
- newTag = new TagByte((byte) 0);
- newTag.load(dIS);
- tags.add(newTag);
- break;
- case Tag.TAG_SHORT:
- newTag = new TagShort((short) 0);
- newTag.load(dIS);
- tags.add(newTag);
- break;
- case Tag.TAG_INT:
- newTag = new TagInteger(0);
- newTag.load(dIS);
- tags.add(newTag);
- break;
- case Tag.TAG_LONG:
- newTag = new TagLong(0);
- newTag.load(dIS);
- tags.add(newTag);
- break;
- case Tag.TAG_DOUBLE:
- newTag = new TagDouble(0);
- newTag.load(dIS);
- tags.add(newTag);
- break;
- }
- tagID = dIS.readByte();
- }
- dIS.close();
- }
- public void addTag(Tag newTag) {
- tags.add(newTag);
- }
- public UUID getUUID() {
- return uUID;
- }
- public File getFile() {
- return file;
- }
- public ArrayList<Tag> getTags() {
- return tags;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement