1 16 17 package de.schlichtherle.io.archive.zip.raes; 18 19 import de.schlichtherle.crypto.io.raes.*; 20 import de.schlichtherle.io.archive.*; 21 import de.schlichtherle.io.archive.spi.*; 22 import de.schlichtherle.io.archive.zip.*; 23 import de.schlichtherle.io.rof.*; 24 25 import java.io.*; 26 import java.util.zip.*; 27 28 import javax.swing.*; 29 30 46 public abstract class AbstractZip32RaesDriver extends JarDriver { 47 48 private final long authenticationTrigger; 49 50 55 protected AbstractZip32RaesDriver() { 56 this(Long.MAX_VALUE); 57 } 58 59 76 protected AbstractZip32RaesDriver(final long authenticationTrigger) { 77 this.authenticationTrigger = authenticationTrigger; 78 } 79 80 84 public final long getAuthenticationTrigger() { 85 return authenticationTrigger; 86 } 87 88 public Icon getOpenIcon(Archive archive) { 89 return UIManager.getIcon("FileView.directoryIcon"); 90 } 91 92 public Icon getClosedIcon(Archive archive) { 93 return UIManager.getIcon("FileView.directoryIcon"); 94 } 95 96 100 public final InputArchive createInputArchive( 101 final Archive archive, 102 final ReadOnlyFile rof) 103 throws UnsupportedEncodingException, FileNotFoundException, IOException { 104 final RaesReadOnlyFile rrof; 105 try { 106 rrof = RaesReadOnlyFile.getInstance(rof, getRaesParameters(archive)); 107 } catch (RaesKeyException failure) { 108 throw new TransientIOException(failure); 109 } 110 111 if (rrof.length() <= getAuthenticationTrigger()) { 112 rrof.authenticate(); 117 } 118 119 return createZip32InputArchive( 120 rrof, getEncoding(), getPreambled(), getPostambled()); 121 } 122 123 abstract protected Zip32InputArchive createZip32InputArchive( 124 ReadOnlyFile rof, 125 String encoding, 126 boolean preambled, 127 boolean postambled) 128 throws NullPointerException , 129 UnsupportedEncodingException, 130 FileNotFoundException, 131 ZipException, 132 IOException; 133 134 138 public final OutputArchive createOutputArchive( 139 final Archive archive, 140 final OutputStream out, 141 final InputArchive source) 142 throws UnsupportedEncodingException, IOException { 143 final RaesOutputStream ros; 144 try { 145 ros = RaesOutputStream.getInstance(out, getRaesParameters(archive)); 146 } catch (RaesKeyException failure) { 147 throw new TransientIOException(failure); 148 } 149 150 return createZip32OutputArchive( 151 ros, getEncoding(), (Zip32InputArchive) source); 152 } 153 154 abstract protected Zip32OutputArchive createZip32OutputArchive( 155 final OutputStream out, 156 final String encoding, 157 final Zip32InputArchive source) 158 throws NullPointerException , 159 UnsupportedEncodingException, 160 IOException; 161 162 172 public RaesParameters getRaesParameters(Archive archive) { 173 return new KeyManagerRaesParameters(archive.getPath()); 174 } 175 } 176 | Popular Tags |