Class LhaImmediateOutputStream

java.lang.Object
java.io.OutputStream
jp.gr.java_conf.dangan.util.lha.LhaImmediateOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class LhaImmediateOutputStream extends OutputStream
???}??????RandomAccessFile?? ???k?f?[?^???o???????????????[?e?B???e?B?N???X?B
java.util.zip.ZipOutputStream ???????C???^?[?t?F?C?X???????????????????B
???k???s??( ???k???T?C?Y?????k?O?T?C?Y?????????????? )???????? ???????s??????????????????B ?????? ???????????R?[?h???????B
 LhaCompressFiles( String arcfile, File[] files ){
   LhaImmediateOutputStream lio = new LhaImmediateOutputStream( arcfile );
 
   for( int i = 0 ; i &lt files.length ; i++ ){
     RandomAccessFile raf = new RandomAccessFile( files[i] );
     LhaHeader header = new LhaHeader( files[i].getName() );
     header.setLastModified( new Date( files.lastModified() ) );
     header.setOriginalSize( files.length() );
     byte[] buffer  = new byte[8192];
     int    length;
 
     while( 0 &lt= ( length = raf.read( buffer ) ) ){
         lio.write( buffer, 0, length );
     }
 
     if( !lio.closeEntry() ){
       header.setCompressMethod( CompressMethod.LH0 );
       lio.putNextEntry( lhaheader );
       raf.seek( 0 );
       while( 0 &lt= ( length = raf.read( buffer ) ) ){
           lio.write( buffer, 0, length );
       }
       lio.closeEntry();
     }
 
   lio.close();
 }
 
?i?????????????????????A?}???????????????N???X?????B?????????i???????????b???? ???????????????\???????????????????B(???????M?K?o?C?g?????f?[?^????????????) LhaRetainedOutputStream ??????????A?}?????????????????????????????v??????????B
?????AJDK 1.1 ???O???? RandomAccessFile ?? setLength ??????????????A ?????f?[?^?????????????f?[?^???????????????t?@?C???T?C?Y???????l?????}?????o??????B
?}???????_???????T?C?Y0???V????t?@?C?????J???????????????????????????????B
 -- revision history --
 $Log: LhaImmediateOutputStream.java,v $
 Revision 1.2  2002/12/11 02:25:06  dangan
 [bug fix]
     jdk1.2 ???R???p?C?????????????????????C???B

 Revision 1.1  2002/12/08 00:00:00  dangan
 [maintenance]
     LhaConstants ???? CompressMethod ?????N???X???????X???????????C???B

 Revision 1.0  2002/08/05 00:00:00  dangan
 add to version control
 [change]
     ?R???X?g???N?^???? ?????? String encode ?????????????p?~?A
     Properties ???????????????????????B
 [maintenance]
     ?\?[?X????
     ?^?u?p?~
     ???C?Z???X????C??

 
Version:
$Revision: 1.2 $
Author:
$Author: dangan $
  • Constructor Summary

    Constructors
    Constructor
    Description
    filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
    ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
    filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
    file?? ???k?f?[?^???o??????OutputStream???\?z?????B
    ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
    file?? ???k?f?[?^???o??????OutputStream???\?z?????B
    ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
    filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
    ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
    filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    ?o???????S?????f?[?^???o?????A?X?g???[??????????B
    ?????A?g?p????????S???????\?[?X???????????B
    boolean
    ?????o???????G???g????????A?????G???g?????o?????\?????????????B
    putNextEntryNotYetCompressed() ???J????G???g????????????? ?}?????\?b?h?????k?????s????(???k???T?C?Y?????k?O?T?C?Y??????????)?????A ?G???g???S?????????????? ?? RandomAccessFile ?????????????B
    ?}?????????????P?? ?t?@?C???|?C???^?? ?G???g???J?n???u?????????????????????? RandomAccessFile ?? setLength() ????? jdk1.1 ???O???? ?G???g?????????k(???????????????k?@)?????o????????????A ?????f?[?^???I?[???~?????k?????s?????s???S???f?[?^???c???????????????B
    void
    ?????????????????G???g?????f?[?^??????I???o???????????o???B ?}???? PostLzssEncoder, LzssOutputStream ???K?????N?? flush() ???????????????????????f?[?^???o???????B (???????????? ?P?????k???????????????????????B)
    void
    ?V????G???g???????????????????X?g???[?????????????B
    ?}?????\?b?h?? ???????k???????G???g?????????? putNextEntryAlreadyCompressed(), ????????k???????????????? putNextEntryNotYetCompressed() ???????o???B
    ???k????????????????????A header.getCompressedSize()
    header.getCRC()
    ???????????????? LhaHeader.UNKNOWN ????????????????k?????????????????B
    header ???????m?? OriginalSize ???w????????????K?v???????B
    void
    ???????k???????G???g?????????}?????????X?g???[?????????????B
    ???k?????f?[?^????????????A?????o?????????????????B
    void
    ????????k???????????G???g?????????}?????????X?g???[???? ?????????Bheader ?? CompressedSize,CRC???w??????????????? ?????????B?}?????\?b?h???n?????? header ???? LhaHeader.setOriginalSize() ???p??? ???m???I???W?i???T?C?Y ???w????????????K?v???????B
    void
    write(byte[] buffer)
    ???????G???g???? buffer?????e???S???????o???B
    void
    write(byte[] buffer, int index, int length)
    ???????G???g???? buffer?? index???? length?o?C?g???f?[?^???????o???B
    void
    write(int data)
    ???????G???g????1?o?C?g???f?[?^???????}???B

    Methods inherited from class java.io.OutputStream

    nullOutputStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LhaImmediateOutputStream

      public LhaImmediateOutputStream(String filename) throws FileNotFoundException
      filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
      ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
      Parameters:
      filename - ???k?f?[?^???????}???t?@?C???????O
      Throws:
      FileNotFoundException - filename ???^?????????t?@?C????????????????????B
      SecurityException - ?Z?L?????e?B?}?l?[?W?????t?@?C???????A?N?Z?X??????????????B
      See Also:
    • LhaImmediateOutputStream

      public LhaImmediateOutputStream(String filename, Properties property) throws FileNotFoundException
      filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
      Parameters:
      filename - ???k?f?[?^???????}???t?@?C???????O
      property - ?e???k?`?????????????????????????????????????v???p?e?B
      Throws:
      FileNotFoundException - filename ???^?????????t?@?C????????????????????B
      SecurityException - ?Z?L?????e?B?}?l?[?W?????t?@?C???????A?N?Z?X??????????????B
      See Also:
    • LhaImmediateOutputStream

      public LhaImmediateOutputStream(File filename) throws IOException
      filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
      ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
      Parameters:
      filename - ???k?f?[?^???????}???t?@?C???????O
      Throws:
      FileNotFoundException - filename ???^?????????t?@?C????????????????????B
      SecurityException - ?Z?L?????e?B?}?l?[?W?????t?@?C???????A?N?Z?X??????????????B
      IOException - JDK1.2 ???R???p?C????????????????????????B
      See Also:
    • LhaImmediateOutputStream

      public LhaImmediateOutputStream(File filename, Properties property) throws IOException
      filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
      Parameters:
      filename - ???k?f?[?^???????}???t?@?C???????O
      property - ?e???k?`?????????????????????????????????????v???p?e?B
      Throws:
      FileNotFoundException - filename ???^?????????t?@?C????????????????????B
      SecurityException - ?Z?L?????e?B?}?l?[?W?????t?@?C???????A?N?Z?X??????????????B
      IOException - JDK1.2 ???R???p?C????????????????????????B
      See Also:
    • LhaImmediateOutputStream

      public LhaImmediateOutputStream(RandomAccessFile file)
      file?? ???k?f?[?^???o??????OutputStream???\?z?????B
      ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
      Parameters:
      file - RandomAccessFile ???C???X?^???X?B
      • ???? close() ?????????????B
      • ?R???X?g???N?^?? mode ???? "rw" ?I?v?V???????g?p?????A ?????}?????????}?????o???????????????????C???X?^???X???????}???B
      ???????????????????B
      See Also:
    • LhaImmediateOutputStream

      public LhaImmediateOutputStream(RandomAccessFile file, Properties property)
      file?? ???k?f?[?^???o??????OutputStream???\?z?????B
      ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
      Parameters:
      file - RandomAccessFile ???C???X?^???X?B
      • ???? close() ?????????????B
      • ?R???X?g???N?^?? mode ???? "rw" ?I?v?V???????g?p?????A ?????}?????????}?????o???????????????????C???X?^???X???????}???B
      ???????????????????B
      property - ?e???k?`?????????????????????????????????????v???p?e?B
      See Also:
  • Method Details

    • write

      public void write(int data) throws IOException
      ???????G???g????1?o?C?g???f?[?^???????}???B
      Specified by:
      write in class OutputStream
      Parameters:
      data - ?????}???f?[?^
      Throws:
      IOException - ???o???G???[??????????????B
    • write

      public void write(byte[] buffer) throws IOException
      ???????G???g???? buffer?????e???S???????o???B
      Overrides:
      write in class OutputStream
      Parameters:
      buffer - ?????o???f?[?^?????????o?C?g?z??
      Throws:
      IOException - ???o???G???[??????????????B
    • write

      public void write(byte[] buffer, int index, int length) throws IOException
      ???????G???g???? buffer?? index???? length?o?C?g???f?[?^???????o???B
      Overrides:
      write in class OutputStream
      Parameters:
      buffer - ?????o???f?[?^?????????o?C?g?z??
      index - buffer?????????o???~???f?[?^???J?n???u
      length - ?f?[?^???o?C?g??
      Throws:
      IOException - ???o???G???[??????????????B
    • flush

      public void flush() throws IOException
      ?????????????????G???g?????f?[?^??????I???o???????????o???B ?}???? PostLzssEncoder, LzssOutputStream ???K?????N?? flush() ???????????????????????f?[?^???o???????B (???????????? ?P?????k???????????????????????B)
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - ???o???G???[?????????????
      See Also:
    • close

      public void close() throws IOException
      ?o???????S?????f?[?^???o?????A?X?g???[??????????B
      ?????A?g?p????????S???????\?[?X???????????B
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException - ???o???G???[?????????????
    • putNextEntry

      public void putNextEntry(LhaHeader header) throws IOException
      ?V????G???g???????????????????X?g???[?????????????B
      ?}?????\?b?h?? ???????k???????G???g?????????? putNextEntryAlreadyCompressed(), ????????k???????????????? putNextEntryNotYetCompressed() ???????o???B
      ???k????????????????????A
      • header.getCompressedSize()
      • header.getCRC()
      ???????????????? LhaHeader.UNKNOWN ????????????????k?????????????????B
      header ???????m?? OriginalSize ???w????????????K?v???????B
      Parameters:
      header - ?????}???G???g????????????????????? LhaHeader???C???X?^???X?B
      Throws:
      IOException - ???o???G???[?????????????
      IllegalArgumentException - header.getOriginalSize() ?? LhaHeader.UNKNOWN ??????????
    • putNextEntryAlreadyCompressed

      public void putNextEntryAlreadyCompressed(LhaHeader header) throws IOException
      ???????k???????G???g?????????}?????????X?g???[?????????????B
      ???k?????f?[?^????????????A?????o?????????????????B
      Parameters:
      header - ?????}???G???g????????????????????? LhaHeader???C???X?^???X?B
      Throws:
      IOException - ???o???G???[?????????????
      IllegalArgumentException -
      1. header.getOriginalSize() ?? LhaHeader.UNKNOWN ??????????
      2. header.getComressedSize() ?? LhaHeader.UNKNOWN ??????????
      3. header.getCRC() ?? LhaHeader.UNKNOWN ??????????
      ?????????B
      IllegalStateException - ???O???G???g????????? closeEntry() ??????????????
    • putNextEntryNotYetCompressed

      public void putNextEntryNotYetCompressed(LhaHeader header) throws IOException
      ????????k???????????G???g?????????}?????????X?g???[???? ?????????Bheader ?? CompressedSize,CRC???w??????????????? ?????????B?}?????\?b?h???n?????? header ???? LhaHeader.setOriginalSize() ???p??? ???m???I???W?i???T?C?Y ???w????????????K?v???????B
      Parameters:
      header - ?????}???G???g????????????????????? LhaHeader???C???X?^???X?B
      Throws:
      IOException - ???o???G???[?????????????
      IllegalArgumentException - header.getOriginalSize() ?? LhaHeader.UNKNOWN ????????????
      IllegalStateException - ???O???G???g????????? closeEntry() ??????????????
    • closeEntry

      public boolean closeEntry() throws IOException
      ?????o???????G???g????????A?????G???g?????o?????\?????????????B
      putNextEntryNotYetCompressed() ???J????G???g????????????? ?}?????\?b?h?????k?????s????(???k???T?C?Y?????k?O?T?C?Y??????????)?????A ?G???g???S?????????????? ?? RandomAccessFile ?????????????B
      ?}?????????????P?? ?t?@?C???|?C???^?? ?G???g???J?n???u?????????????????????? RandomAccessFile ?? setLength() ????? jdk1.1 ???O???? ?G???g?????????k(???????????????k?@)?????o????????????A ?????f?[?^???I?[???~?????k?????s?????s???S???f?[?^???c???????????????B
      Returns:
      ?G???g?????o?????????????? true?A ???k?O?????????k?????????T?C?Y???????????????????A ?G???g???????????????????? false?B ?????A?????????????G???g?????????????????? true ???????B
      Throws:
      IOException - ???o???G???[?????????????