<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    I/O Compression

    public class GZIPcompress {

        
    public static void main(String[] args) throws IOException {

            BufferedReader in 
    = new BufferedReader(
                    
    new FileReader("test.txt"));
            BufferedOutputStream out 
    = new BufferedOutputStream(
                    
    new GZIPOutputStream(new FileOutputStream("test.gz")));
            System.out.println(
    "Writing file");
            
    int c;
            
    while((c = in.read())!=-1){
                out.write(c);
            }
            in.close();
            out.close();
            
            System.out.println(
    "Reading file");
            BufferedReader in2 
    = new BufferedReader(
                    
    new InputStreamReader(new GZIPInputStream(new FileInputStream("test.gz"))));
            String s;
            
    while((s=in2.readLine())!=null){
                System.out.println(s);
            }
        }
    }
    The use of the compression classes is straightforward; you simply wrap your output stream in a GZIPOutputStream or ZipOutputStream, and your input stream in a GZIPInputStream or ZipInputStream. All else is ordinary I/O reading and writing. This is an example of mixing the char-oriented streams with the byte-oriented streams; in uses the Reader classes, whereas GZIPOutputStream’s constructor can accept only an OutputStream object, not a Writer object. When the file is opened, the GZIPInputStream is converted to a Reader.



    Multifile storage with Zip
    it shows the use of the Checksum classes to calculate and verify the checksum for the file. There are two Checksum types: Adler32 (which is faster) and CRC32 (which is slower but slightly more accurate).

    /**
     * Uses ZIP compression to compress any number of files given on the command line.
     * 
    @author WPeng
     *
     * 
    @since 2012-11-8
     
    */
    public class ZipCompress {

        
    public static void main(String[] args) throws IOException{
            FileOutputStream f 
    = new FileOutputStream("test.zip");
            CheckedOutputStream csum 
    = new CheckedOutputStream(f, new Adler32());
            ZipOutputStream zos 
    = new ZipOutputStream(csum);
            BufferedOutputStream out 
    = new BufferedOutputStream(zos);
            zos.setComment(
    "A test of Java Zipping");
            
            
    // No corresponding getComment(), though
            for(String arg : args){
                System.out.println(
    "Wrting file " + arg);
                BufferedReader in 
    = new BufferedReader(new FileReader(arg));
                zos.putNextEntry(
    new ZipEntry(arg));
                
    int c;
                
    while((c = in.read())!=-1)
                    out.write(c);
                in.close();
                out.flush();
            }
            
    // Checksum valid only after the file has been closed!
            System.out.println("Checksum: " + csum.getChecksum().getValue());
            
            
    // Now extract the files:
            System.out.println("Reading file");
            FileInputStream fin 
    = new FileInputStream("test.zip");
            CheckedInputStream csumi 
    = new CheckedInputStream(fin, new Adler32());
            ZipInputStream in2 
    = new ZipInputStream(csumi);
            BufferedInputStream bis 
    = new BufferedInputStream(in2);
            ZipEntry ze;
            
    while((ze = in2.getNextEntry()) != null){
                System.out.println(
    "Reading file " + ze);
                
    int x;
                
    while((x=bis.read()) != -1)
                    System.out.println(x);
            }
            
            
    if(args.length==1){
                System.out.println(
    "Checksum: " + csumi.getChecksum().getValue());
            }
            bis.close();
            
            
    // Alternative way to open and read Zip files:
            ZipFile zf = new ZipFile("test.zip");
            Enumeration e 
    = zf.entries();
            
    while(e.hasMoreElements()){
                ZipEntry ze2 
    = (ZipEntry)e.nextElement();
                System.out.println(
    "File: "+ ze2);
                
    // and extract the data as before
            }        
            
        }
    }
    • For each file to add to the archive, you must call putNextEntry( ) and pass it a ZipEntry object.
    • The ZipEntry object contains an extensive interface that allows you to get and set all the data available on that particular entry in your Zip file: name, compressed and uncompressed sizes, date, CRC checksum, extra field data, comment, compression method, and whether it’s a directory entry.
    • CheckedInputStream and CheckedOutputStream support both Adler32 and CRC32 checksums, the ZipEntry class supports only an interface for CRC
    • To extract files, ZipInputStream has a getNextEntry( ) method that returns the next ZipEntry if there is one


    JAR files are cross-platform, so you don’t need to worry about platform issues. You can also include audio and image files as well as class files.
    JAR files are particularly helpful when you deal with the Internet.
    jar [options] destination [manifest] inputfile(s)


    1. Here are some typical ways to invoke jar. The following command creates a JAR file called myJarFile.jar that contains all of the class files in the current directory, along with an automatically generated manifest file:
      jar cf myJarFile.jar *.class
    2. The next command is like the previous example, but it adds a user-created manifest file called myManifestFile.mf:
      jar cmf myJarFile.jar myManifestFile.mf *.class
    3. This produces a table of contents of the files in myJarFile.jar:
      jar tf myJarFile.jar
    4. This adds the "verbose" flag to give more detailed information about the files in myJarFile.jar:
      jar tvf myJarFile.jar
    5. Assuming audio, classes, and image are subdirectories, this combines all of the subdirectories into the file myApp.jar. The "verbose" flag is also included to give extra feedback while the jar program is working:
      jar cvf myApp.jar audio classes image
    a JAR file created on one platform will be transparently readable by the jar tool on any other platform (a problem that sometimes plagues Zip utilities).










    posted on 2012-11-08 09:30 鹽城小土包 閱讀(163) 評論(0)  編輯  收藏 所屬分類: J2EE

    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導航

    統計

    常用鏈接

    留言簿

    隨筆檔案(14)

    文章分類(18)

    文章檔案(18)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 久久精品视频免费| 国产精品无码免费视频二三区 | 国拍在线精品视频免费观看| 亚洲xxxx视频| 亚洲av麻豆aⅴ无码电影| 无码日韩精品一区二区三区免费| 亚洲综合色区中文字幕| 亚洲AⅤ视频一区二区三区| 午夜视频免费在线观看| 自拍偷自拍亚洲精品播放| 亚洲AV无码日韩AV无码导航| 女人张腿给男人桶视频免费版| 国产精品玖玖美女张开腿让男人桶爽免费看| 久久久久久亚洲精品成人| 亚洲av无码成人精品区在线播放 | 久久亚洲成a人片| 免费看大美女大黄大色| 麻豆精品成人免费国产片| 亚洲AV噜噜一区二区三区 | 久久久精品视频免费观看| 亚洲av无码专区在线| 亚洲午夜未满十八勿入网站2| 久久久www成人免费毛片| 免费无码av片在线观看| 午夜亚洲WWW湿好爽| 亚洲精品国产情侣av在线| 久久久精品国产亚洲成人满18免费网站| 青青视频观看免费99| 永久免费av无码网站yy| 美女免费精品高清毛片在线视| 亚洲系列中文字幕| 国产亚洲福利精品一区| 免费国产在线观看| 亚洲中文无码永久免费| 亚洲国产精品免费视频| 国产三级在线免费观看| 欧洲亚洲国产精华液| 亚洲一区在线视频| 亚洲精彩视频在线观看| 亚洲国产精品无码久久SM| 亚洲M码 欧洲S码SSS222|