blob: 00b7a4834a7afb163465c5b40eaf53ca79f35663 [file] [edit]
/*
* Copyright (c) 2014-2021 by Wen Yu
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License, v. 2.0 are satisfied: GNU General Public License, version 2
* or any later version.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
*/
package pixy.image.tiff;
import java.io.IOException;
import pixy.io.RandomAccessOutputStream;
import pixy.string.StringUtils;
public abstract class AbstractByteField extends TiffField<byte[]> {
public AbstractByteField(short tag, FieldType fieldType, byte[] data) {
super(tag, fieldType, data.length);
this.data = data;
}
public byte[] getData() {
return data.clone();
}
public String getDataAsString() {
return StringUtils.byteArrayToHexString(data, 0, MAX_STRING_REPR_LEN);
}
protected int writeData(RandomAccessOutputStream os, int toOffset) throws IOException {
if (data.length <= 4) {
dataOffset = (int)os.getStreamPointer();
byte[] tmp = new byte[4];
System.arraycopy(data, 0, tmp, 0, data.length);
os.write(tmp);
} else {
dataOffset = toOffset;
os.writeInt(toOffset);
os.seek(toOffset);
os.write(data);
toOffset += data.length;
}
return toOffset;
}
}