| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app; |
| 18 |
|
| 19 |
import java.io.IOException; |
| 20 |
import java.nio.ByteBuffer; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class SectionWriter implements ImgFileWriter { |
| 29 |
|
| 30 |
private final ImgFileWriter writer; |
| 31 |
private final Section section; |
| 32 |
private final int secStart; |
| 33 |
|
| 34 |
public SectionWriter(ImgFileWriter writer, Section section) { |
| 35 |
this.writer = writer; |
| 36 |
this.secStart = section.getPosition(); |
| 37 |
this.section = section; |
| 38 |
} |
| 39 |
|
| 40 |
public void sync() throws IOException { |
| 41 |
writer.sync(); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public void close() { |
| 48 |
if (section != null) |
| 49 |
section.setSize(writer.position() - secStart); |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
public int position() { |
| 54 |
return writer.position() - secStart; |
| 55 |
} |
| 56 |
|
| 57 |
public void position(long pos) { |
| 58 |
writer.position(pos + secStart); |
| 59 |
} |
| 60 |
|
| 61 |
public void put(byte b) { |
| 62 |
writer.put(b); |
| 63 |
} |
| 64 |
|
| 65 |
public void put1s(int val) { |
| 66 |
writer.put1s(val); |
| 67 |
} |
| 68 |
|
| 69 |
public void put2s(int val) { |
| 70 |
writer.put2s(val); |
| 71 |
} |
| 72 |
|
| 73 |
public void put3s(int val) { |
| 74 |
writer.put3s(val); |
| 75 |
} |
| 76 |
|
| 77 |
public void put1u(int val) { |
| 78 |
writer.put1u(val); |
| 79 |
} |
| 80 |
|
| 81 |
public void put2u(int val) { |
| 82 |
writer.put2u(val); |
| 83 |
} |
| 84 |
|
| 85 |
public void put3u(int val) { |
| 86 |
writer.put3u(val); |
| 87 |
} |
| 88 |
|
| 89 |
public void putNu(int nBytes, int val) { |
| 90 |
writer.putNu(nBytes, val); |
| 91 |
} |
| 92 |
|
| 93 |
public void put4(int val) { |
| 94 |
writer.put4(val); |
| 95 |
} |
| 96 |
|
| 97 |
public void put(byte[] val) { |
| 98 |
writer.put(val); |
| 99 |
} |
| 100 |
|
| 101 |
public void put(byte[] src, int start, int length) { |
| 102 |
writer.put(src, start, length); |
| 103 |
} |
| 104 |
|
| 105 |
public void put(ByteBuffer src) { |
| 106 |
writer.put(src); |
| 107 |
} |
| 108 |
|
| 109 |
public long getSize() { |
| 110 |
throw new UnsupportedOperationException("Cannot get size at this point"); |
| 111 |
} |
| 112 |
} |