1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.tiff.write;
18
19 import java.io.IOException;
20
21 import org.apache.commons.imaging.ImagingException;
22 import org.apache.commons.imaging.common.BinaryOutputStream;
23
24 abstract class AbstractTiffOutputItem {
25
26 public static class Value extends AbstractTiffOutputItem {
27
28 static final int SHALLOW_SIZE = 32;
29 private final byte[] bytes;
30 private final String name;
31
32 Value(final String name, final byte[] bytes) {
33 this.name = name;
34 this.bytes = bytes;
35 }
36
37 @Override
38 public String getItemDescription() {
39 return name;
40 }
41
42 @Override
43 public int getItemLength() {
44 return bytes.length;
45 }
46
47 public void updateValue(final byte[] bytes) throws ImagingException {
48 if (this.bytes.length != bytes.length) {
49 throw new ImagingException("Updated data size mismatch: " + this.bytes.length + " vs. " + bytes.length);
50 }
51 System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
52 }
53
54 @Override
55 public void writeItem(final BinaryOutputStream bos) throws IOException, ImagingException {
56 bos.write(bytes);
57 }
58 }
59
60 public static final long UNDEFINED_VALUE = -1;
61
62 private long offset = UNDEFINED_VALUE;
63
64 public abstract String getItemDescription();
65
66 public abstract int getItemLength();
67
68 protected long getOffset() {
69 return offset;
70 }
71
72 protected void setOffset(final long offset) {
73 this.offset = offset;
74 }
75
76 public abstract void writeItem(BinaryOutputStream bos) throws IOException, ImagingException;
77 }