Class LhaImmediateOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class LhaImmediateOutputStream
    extends java.io.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 < 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 <= ( length = raf.read( buffer ) ) ){
             lio.write( buffer, 0, length );
         }
     
         if( !lio.closeEntry() ){
           header.setCompressMethod( CompressMethod.LH0 );
           lio.putNextEntry( lhaheader );
           raf.seek( 0 );
           while( 0 <= ( 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
      LhaImmediateOutputStream​(java.io.File filename)
      filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
      ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
      LhaImmediateOutputStream​(java.io.File filename, java.util.Properties property)
      filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
      LhaImmediateOutputStream​(java.io.RandomAccessFile file)
      file?? ???k?f?[?^???o??????OutputStream???\?z?????B
      ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
      LhaImmediateOutputStream​(java.io.RandomAccessFile file, java.util.Properties property)
      file?? ???k?f?[?^???o??????OutputStream???\?z?????B
      ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
      LhaImmediateOutputStream​(java.lang.String filename)
      filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
      ?e???k?`?????????????????????????????????v???p?e?B???? LhaProperty.getProperties() ???????????v???p?e?B???g?p???????B
      LhaImmediateOutputStream​(java.lang.String filename, java.util.Properties property)
      filename ???t?@?C???? ???k?f?[?^???o??????OutputStream???\?z?????B
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      ?o???????S?????f?[?^???o?????A?X?g???[??????????B
      ?????A?g?p????????S???????\?[?X???????????B
      boolean closeEntry()
      ?????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 flush()
      ?????????????????G???g?????f?[?^??????I???o???????????o???B ?}???? PostLzssEncoder, LzssOutputStream ???K?????N?? flush() ???????????????????????f?[?^???o???????B (???????????? ?P?????k???????????????????????B)
      void putNextEntry​(LhaHeader header)
      ?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 putNextEntryAlreadyCompressed​(LhaHeader header)
      ???????k???????G???g?????????}?????????X?g???[?????????????B
      ???k?????f?[?^????????????A?????o?????????????????B
      void putNextEntryNotYetCompressed​(LhaHeader header)
      ????????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 Detail

      • LhaImmediateOutputStream

        public LhaImmediateOutputStream​(java.lang.String filename)
                                 throws java.io.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:
        java.io.FileNotFoundException - filename ???^?????????t?@?C????????????????????B
        java.lang.SecurityException - ?Z?L?????e?B?}?l?[?W?????t?@?C???????A?N?Z?X??????????????B
        See Also:
        LhaProperty.getProperties()
      • LhaImmediateOutputStream

        public LhaImmediateOutputStream​(java.lang.String filename,
                                        java.util.Properties property)
                                 throws java.io.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:
        java.io.FileNotFoundException - filename ???^?????????t?@?C????????????????????B
        java.lang.SecurityException - ?Z?L?????e?B?}?l?[?W?????t?@?C???????A?N?Z?X??????????????B
        See Also:
        LhaProperty
      • LhaImmediateOutputStream

        public LhaImmediateOutputStream​(java.io.File filename)
                                 throws java.io.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:
        java.io.FileNotFoundException - filename ???^?????????t?@?C????????????????????B
        java.lang.SecurityException - ?Z?L?????e?B?}?l?[?W?????t?@?C???????A?N?Z?X??????????????B
        java.io.IOException - JDK1.2 ???R???p?C????????????????????????B
        See Also:
        LhaProperty.getProperties()
      • LhaImmediateOutputStream

        public LhaImmediateOutputStream​(java.io.File filename,
                                        java.util.Properties property)
                                 throws java.io.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:
        java.io.FileNotFoundException - filename ???^?????????t?@?C????????????????????B
        java.lang.SecurityException - ?Z?L?????e?B?}?l?[?W?????t?@?C???????A?N?Z?X??????????????B
        java.io.IOException - JDK1.2 ???R???p?C????????????????????????B
        See Also:
        LhaProperty
      • LhaImmediateOutputStream

        public LhaImmediateOutputStream​(java.io.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:
        LhaProperty.getProperties()
      • LhaImmediateOutputStream

        public LhaImmediateOutputStream​(java.io.RandomAccessFile file,
                                        java.util.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:
        LhaProperty
    • Method Detail

      • write

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

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

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

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

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

        public void putNextEntry​(LhaHeader header)
                          throws java.io.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:
        java.io.IOException - ???o???G???[?????????????
        java.lang.IllegalArgumentException - header.getOriginalSize() ?? LhaHeader.UNKNOWN ??????????
      • putNextEntryAlreadyCompressed

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

        public void putNextEntryNotYetCompressed​(LhaHeader header)
                                          throws java.io.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:
        java.io.IOException - ???o???G???[?????????????
        java.lang.IllegalArgumentException - header.getOriginalSize() ?? LhaHeader.UNKNOWN ????????????
        java.lang.IllegalStateException - ???O???G???g????????? closeEntry() ??????????????
      • closeEntry

        public boolean closeEntry()
                           throws java.io.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:
        java.io.IOException - ???o???G???[?????????????