001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.imaging.formats.tiff;
018
019import java.util.Comparator;
020
021public abstract class AbstractTiffElement {
022    public abstract static class DataElement extends AbstractTiffElement {
023        private final byte[] data;
024
025        public DataElement(final long offset, final int length, final byte[] data) {
026            super(offset, length);
027
028            this.data = data;
029        }
030
031        public byte[] getData() {
032            return data.clone();
033        }
034
035        public int getDataLength() {
036            return data.length;
037        }
038    }
039
040    public static final class Stub extends AbstractTiffElement {
041        public Stub(final long offset, final int length) {
042            super(offset, length);
043        }
044
045        @Override
046        public String getElementDescription() {
047            return "Element, offset: " + offset + ", length: " + length + ", last: " + (offset + length);
048        }
049
050    }
051
052    public static final Comparator<AbstractTiffElement> COMPARATOR = Comparator.comparingLong(e -> e.offset);
053
054    public final long offset;
055
056    public final int length;
057
058    public AbstractTiffElement(final long offset, final int length) {
059        this.offset = offset;
060        this.length = length;
061    }
062
063    public abstract String getElementDescription();
064}