1 /*****************************************************************
2 |
3 |    Copyright 2002-2008 Axiomatic Systems, LLC
4 |
5 |    $Id: SchmAtom.java 196 2008-10-14 22:59:31Z bok $
6 |
7 |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
8 |
9 |    Unless you have obtained Bento4 under a difference license,
10 |    this version of Bento4 is Bento4|GPL.
11 |    Bento4|GPL is free software; you can redistribute it and/or modify
12 |    it under the terms of the GNU General Public License as published by
13 |    the Free Software Foundation; either version 2, or (at your option)
14 |    any later version.
15 |
16 |    Bento4|GPL is distributed in the hope that it will be useful,
17 |    but WITHOUT ANY WARRANTY; without even the implied warranty of
18 |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 |    GNU General Public License for more details.
20 |
21 |    You should have received a copy of the GNU General Public License
22 |    along with Bento4|GPL; see the file COPYING.  If not, write to the
23 |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 |    02111-1307, USA.
25 |
26 ****************************************************************/
27 
28 package com.axiosys.bento4;
29 
30 import java.io.DataOutputStream;
31 import java.io.IOException;
32 import java.io.RandomAccessFile;
33 
34 
35 public class SchmAtom extends Atom {
36     private int    schemeType;
37     private int    schemeVersion;
38     private String schemeUri;
39 
SchmAtom(int size, RandomAccessFile source)40     public SchmAtom(int size, RandomAccessFile source) throws IOException {
41         super(TYPE_SCHM, size, true, source);
42 
43         schemeType = source.readInt();
44         schemeVersion = source.readInt();
45 
46         byte[] str = new byte[size-getHeaderSize()-8];
47         source.read(str);
48         int str_size = 0;
49         while (str_size < str.length && str[str_size] != 0) str_size++;
50         schemeUri = new String(str, 0, str_size, "UTF-8");
51 
52     }
53 
getSchemeType()54     public int getSchemeType() {
55         return schemeType;
56     }
57 
getSchemeUri()58     public String getSchemeUri() {
59         return schemeUri;
60     }
61 
getSchemeVersion()62     public int getSchemeVersion() {
63         return schemeVersion;
64     }
65 
writeFields(DataOutputStream stream)66     protected void writeFields(DataOutputStream stream) throws IOException {
67         stream.writeInt(schemeType);
68         stream.writeInt(schemeVersion);
69         byte[] uri_bytes = schemeUri.getBytes("UTF-8");
70         stream.write(uri_bytes);
71         int termination = size-getHeaderSize()-8-uri_bytes.length;
72         for (int i=0; i<termination; i++) {
73             stream.writeByte(0);
74         }
75     }
76 
toString(String indentation)77     public String toString(String indentation) {
78         StringBuffer result = new StringBuffer(super.toString(indentation));
79         result.append("\n" + indentation + "  scheme_type    = " + Atom.typeString(schemeType));
80         result.append("\n" + indentation + "  scheme_version = " + schemeVersion);
81         result.append("\n" + indentation + "  scheme_uri     = " + schemeUri);
82         return result.toString();
83     }
84 }
85