OSDN Git Service

Add new source files
[armadillo/armadillo1.git] / src / jp / sfjp / armadillo / archive / tar / TarOutputStream.java
1 package jp.sfjp.armadillo.archive.tar;
2
3 import java.io.*;
4 import jp.sfjp.armadillo.archive.*;
5
6 public final class TarOutputStream extends ArchiveOutputStream {
7
8     private TarHeader header;
9     private TarEntry nextEntry;
10
11     public TarOutputStream(OutputStream os) {
12         super(os);
13         this.header = new TarHeader();
14         frontStream = os;
15     }
16
17     public void putNextEntry(TarEntry entry) throws IOException {
18         ensureOpen();
19         nextEntry = entry;
20         header.write(this, entry);
21         written = 0;
22     }
23
24     public void closeEntry() throws IOException {
25         ensureOpen();
26         int skipSize = (int)TarHeader.getSkipSize(nextEntry.getSize());
27         write(new byte[skipSize]);
28         flush();
29         nextEntry = null;
30     }
31
32     @Override
33     public void close() throws IOException {
34         try {
35             header.writeEndOfArchive(this);
36         }
37         finally {
38             try {
39                 super.close();
40             }
41             finally {
42                 header = null;
43                 nextEntry = null;
44             }
45         }
46     }
47
48 }