Home | History | Annotate | Download | only in ultraviolet
      1 /*
      2  * Copyright 2011 castLabs, Berlin
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the License);
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an AS IS BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.googlecode.mp4parser.boxes.ultraviolet;
     18 
     19 import com.coremedia.iso.IsoTypeReader;
     20 import com.coremedia.iso.Utf8;
     21 import com.googlecode.mp4parser.AbstractFullBox;
     22 
     23 import java.nio.ByteBuffer;
     24 
     25 /**
     26  *
     27  */
     28 public class BaseLocationBox extends AbstractFullBox {
     29     String baseLocation = "";
     30     String purchaseLocation = "";
     31 
     32     public BaseLocationBox() {
     33         super("bloc");
     34     }
     35 
     36     public BaseLocationBox(String baseLocation, String purchaseLocation) {
     37         super("bloc");
     38         this.baseLocation = baseLocation;
     39         this.purchaseLocation = purchaseLocation;
     40     }
     41 
     42     public String getBaseLocation() {
     43         return baseLocation;
     44     }
     45 
     46     public void setBaseLocation(String baseLocation) {
     47         this.baseLocation = baseLocation;
     48     }
     49 
     50     public String getPurchaseLocation() {
     51         return purchaseLocation;
     52     }
     53 
     54     public void setPurchaseLocation(String purchaseLocation) {
     55         this.purchaseLocation = purchaseLocation;
     56     }
     57 
     58     @Override
     59     protected long getContentSize() {
     60         return 1028;
     61     }
     62 
     63     @Override
     64     public void _parseDetails(ByteBuffer content) {
     65         parseVersionAndFlags(content);
     66         baseLocation = IsoTypeReader.readString(content);
     67         content.get(new byte[256 - Utf8.utf8StringLengthInBytes(baseLocation) - 1]);
     68         purchaseLocation = IsoTypeReader.readString(content);
     69         content.get(new byte[256 - Utf8.utf8StringLengthInBytes(purchaseLocation) - 1]);
     70         content.get(new byte[512]);
     71     }
     72 
     73     @Override
     74     protected void getContent(ByteBuffer byteBuffer) {
     75         writeVersionAndFlags(byteBuffer);
     76         byteBuffer.put(Utf8.convert(baseLocation));
     77         byteBuffer.put(new byte[256 - Utf8.utf8StringLengthInBytes(baseLocation)]); // string plus term zero
     78         byteBuffer.put(Utf8.convert(purchaseLocation));
     79         byteBuffer.put(new byte[256 - Utf8.utf8StringLengthInBytes(purchaseLocation)]); // string plus term zero
     80         byteBuffer.put(new byte[512]);
     81     }
     82 
     83     @Override
     84     public boolean equals(Object o) {
     85         if (this == o) return true;
     86         if (o == null || getClass() != o.getClass()) return false;
     87 
     88         BaseLocationBox that = (BaseLocationBox) o;
     89 
     90         if (baseLocation != null ? !baseLocation.equals(that.baseLocation) : that.baseLocation != null) return false;
     91         if (purchaseLocation != null ? !purchaseLocation.equals(that.purchaseLocation) : that.purchaseLocation != null)
     92             return false;
     93 
     94         return true;
     95     }
     96 
     97     @Override
     98     public int hashCode() {
     99         int result = baseLocation != null ? baseLocation.hashCode() : 0;
    100         result = 31 * result + (purchaseLocation != null ? purchaseLocation.hashCode() : 0);
    101         return result;
    102     }
    103 }
    104