| Revision | 144 (tree) |
|---|---|
| Time | 2015-11-17 23:03:24 |
| Author | t_nakayama1971 |
(empty log message)
| @@ -1,20 +1,16 @@ | ||
| 1 | 1 | package core.file; |
| 2 | 2 | |
| 3 | -import java.io.FilterOutputStream; | |
| 4 | 3 | import java.io.IOException; |
| 5 | 4 | import java.io.OutputStream; |
| 6 | 5 | import java.nio.charset.Charset; |
| 7 | - | |
| 8 | 6 | import java.util.zip.ZipEntry; |
| 9 | 7 | import java.util.zip.ZipOutputStream; |
| 10 | 8 | |
| 11 | -import core.config.Factory; | |
| 12 | - | |
| 13 | 9 | /** |
| 14 | 10 | * 改行テキスト出力(Zip) |
| 15 | 11 | * @author Tadashi Nakayama |
| 16 | 12 | */ |
| 17 | -public final class ZippedLineOutputStream extends FilterOutputStream { | |
| 13 | +public final class ZippedLineOutputStream extends ZipOutputStream { | |
| 18 | 14 | |
| 19 | 15 | /** ページ内最大数 */ |
| 20 | 16 | private int line = -1; |
| @@ -28,6 +24,8 @@ | ||
| 28 | 24 | private int prev = 0; |
| 29 | 25 | /** ページタイトル */ |
| 30 | 26 | private byte[] title; |
| 27 | + /** タイトル出力フラグ */ | |
| 28 | + private boolean titleFlg; | |
| 31 | 29 | |
| 32 | 30 | /** |
| 33 | 31 | * コンストラクタ |
| @@ -34,7 +32,7 @@ | ||
| 34 | 32 | * @param os OutputStream |
| 35 | 33 | */ |
| 36 | 34 | public ZippedLineOutputStream(final OutputStream os) { |
| 37 | - super(getZipOutputStream(os)); | |
| 35 | + super(os); | |
| 38 | 36 | } |
| 39 | 37 | |
| 40 | 38 | /** |
| @@ -43,28 +41,24 @@ | ||
| 43 | 41 | * @param val Charset |
| 44 | 42 | */ |
| 45 | 43 | public ZippedLineOutputStream(final OutputStream os, final Charset val) { |
| 46 | - super(getZipOutputStream(os, val)); | |
| 44 | + super(os, val); | |
| 47 | 45 | } |
| 48 | 46 | |
| 49 | 47 | /** |
| 50 | - * ZipOutputStream取得 | |
| 51 | - * @param os OutputStream | |
| 52 | - * @return ZipOutputStream | |
| 48 | + * @see java.io.FilterOutputStream#write(byte[]) | |
| 53 | 49 | */ |
| 54 | - private static ZipOutputStream getZipOutputStream(final OutputStream os) { | |
| 55 | - return Factory.construct(Factory.getConstructor( | |
| 56 | - ZipOutputStream.class, OutputStream.class), os); | |
| 50 | + @Override | |
| 51 | + public void write(final byte[] b) throws IOException { | |
| 52 | + throw new UnsupportedOperationException(); | |
| 57 | 53 | } |
| 58 | 54 | |
| 59 | 55 | /** |
| 60 | - * ZipOutputStream取得 | |
| 61 | - * @param os OutputStream | |
| 62 | - * @param val Charset | |
| 63 | - * @return ZipOutputStream | |
| 56 | + * @see java.util.zip.ZipOutputStream#write(byte[], int, int) | |
| 64 | 57 | */ |
| 65 | - private static ZipOutputStream getZipOutputStream(final OutputStream os, final Charset val) { | |
| 66 | - return Factory.construct(Factory.getConstructor( | |
| 67 | - ZipOutputStream.class, OutputStream.class, Charset.class), os, val); | |
| 58 | + @Override | |
| 59 | + public synchronized void write( | |
| 60 | + final byte[] b, final int off, final int len) throws IOException { | |
| 61 | + throw new UnsupportedOperationException(); | |
| 68 | 62 | } |
| 69 | 63 | |
| 70 | 64 | /** |
| @@ -73,9 +67,9 @@ | ||
| 73 | 67 | @Override |
| 74 | 68 | public void write(final int b) throws IOException { |
| 75 | 69 | if (this.line == this.count) { |
| 76 | - putNextEntry(true); | |
| 70 | + putNextEntry(getEntry(true)); | |
| 77 | 71 | } else if (!hasEntry()) { |
| 78 | - putNextEntry(false); | |
| 72 | + putNextEntry(getEntry(false)); | |
| 79 | 73 | } |
| 80 | 74 | |
| 81 | 75 | super.out.write(b); |
| @@ -120,25 +114,27 @@ | ||
| 120 | 114 | * エントリ終了 |
| 121 | 115 | * @throws IOException IO例外 |
| 122 | 116 | */ |
| 117 | + @Override | |
| 123 | 118 | public void finish() throws IOException { |
| 124 | 119 | if (hasEntry()) { |
| 125 | - getZipStream().closeEntry(); | |
| 126 | - getZipStream().finish(); | |
| 120 | + super.closeEntry(); | |
| 121 | + super.finish(); | |
| 127 | 122 | } |
| 128 | 123 | } |
| 129 | 124 | |
| 130 | 125 | /** |
| 131 | 126 | * エントリ設定 |
| 132 | - * @param flg タイトル出力フラグ | |
| 127 | + * @param ze ZipEntry | |
| 133 | 128 | * @throws IOException IO例外 |
| 134 | 129 | */ |
| 135 | - public void putNextEntry(final boolean flg) throws IOException { | |
| 130 | + @Override | |
| 131 | + public void putNextEntry(final ZipEntry ze) throws IOException { | |
| 136 | 132 | if (hasEntry()) { |
| 137 | - getZipStream().closeEntry(); | |
| 133 | + super.closeEntry(); | |
| 138 | 134 | } |
| 139 | 135 | |
| 140 | - getZipStream().putNextEntry(getEntry(this.entries)); | |
| 141 | - outputTitle(flg); | |
| 136 | + super.putNextEntry(ze); | |
| 137 | + outputTitle(); | |
| 142 | 138 | |
| 143 | 139 | this.count = 0; |
| 144 | 140 | this.entries++; |
| @@ -146,11 +142,10 @@ | ||
| 146 | 142 | |
| 147 | 143 | /** |
| 148 | 144 | * タイトル出力 |
| 149 | - * @param flg タイトル出力フラグ | |
| 150 | 145 | * @throws IOException IO例外 |
| 151 | 146 | */ |
| 152 | - private void outputTitle(final boolean flg) throws IOException { | |
| 153 | - if (this.title != null && flg) { | |
| 147 | + private void outputTitle() throws IOException { | |
| 148 | + if (this.title != null && this.titleFlg) { | |
| 154 | 149 | super.out.write(this.title); |
| 155 | 150 | } |
| 156 | 151 | } |
| @@ -164,25 +159,18 @@ | ||
| 164 | 159 | } |
| 165 | 160 | |
| 166 | 161 | /** |
| 167 | - * ZipOutputStream取得 | |
| 168 | - * @return ZipOutputStream | |
| 169 | - */ | |
| 170 | - private ZipOutputStream getZipStream() { | |
| 171 | - return ZipOutputStream.class.cast(super.out); | |
| 172 | - } | |
| 173 | - | |
| 174 | - /** | |
| 175 | 162 | * ZipEntry取得 |
| 176 | - * @param entry エントリ数 | |
| 163 | + * @param flg タイトル出力フラグ | |
| 177 | 164 | * @return ZipEntry |
| 178 | 165 | */ |
| 179 | - private ZipEntry getEntry(final int entry) { | |
| 166 | + public ZipEntry getEntry(final boolean flg) { | |
| 167 | + this.titleFlg = flg; | |
| 180 | 168 | String str = this.name; |
| 181 | 169 | int loc = str.lastIndexOf('.'); |
| 182 | 170 | if (0 <= loc) { |
| 183 | - str = str.substring(0, loc).trim() + addEntry(entry) + str.substring(loc); | |
| 171 | + str = str.substring(0, loc).trim() + addEntry(this.entries) + str.substring(loc); | |
| 184 | 172 | } else { |
| 185 | - str = str + addEntry(entry); | |
| 173 | + str = str + addEntry(this.entries); | |
| 186 | 174 | } |
| 187 | 175 | return new ZipEntry(str); |
| 188 | 176 | } |
| @@ -110,7 +110,7 @@ | ||
| 110 | 110 | } |
| 111 | 111 | if (entry != null) { |
| 112 | 112 | getZipStream().setEntryName(entry); |
| 113 | - getZipStream().putNextEntry(true); | |
| 113 | + getZipStream().putNextEntry(getZipStream().getEntry(true)); | |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 |