<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 鹽城小土包 閱讀(157) 評論(0)  編輯  收藏 所屬分類: J2EE

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿

    隨筆檔案(14)

    文章分類(18)

    文章檔案(18)

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产精品亚洲玖玖玖在线观看 | 亚洲AV无码AV男人的天堂不卡| 日韩免费观看一区| 亚洲人成精品久久久久| 国产精品一区二区三区免费| 综合亚洲伊人午夜网| 中文字幕免费在线视频| 亚洲高清国产拍精品26U| 久久免费福利视频| 亚洲成aⅴ人片在线观| 毛片免费视频观看| 国产精品亚洲色图| 久久久久亚洲AV综合波多野结衣| a级毛片视频免费观看| 久久亚洲AV成人无码电影| 曰曰鲁夜夜免费播放视频| 亚洲中文字幕无码mv| 亚洲第一区精品观看| 国产在线观看免费av站| 久久精品国产亚洲av麻豆小说| 在线观看免费人成视频| 福利片免费一区二区三区| 久久国产亚洲精品麻豆| 日韩欧毛片免费视频| 国产精品亚洲色婷婷99久久精品| 国产AV无码专区亚洲AWWW| 亚洲视频免费播放| 国产精品亚洲片在线花蝴蝶| 国产AV无码专区亚洲AVJULIA| 国产大片91精品免费观看不卡| 亚洲AV网一区二区三区 | 日韩人妻无码精品久久免费一| 国产成人亚洲合集青青草原精品| 国产女高清在线看免费观看| a级毛片视频免费观看| 亚洲乱妇熟女爽到高潮的片| 国产aⅴ无码专区亚洲av麻豆| 日本h在线精品免费观看| 无码天堂亚洲国产AV| 亚洲国产精品人久久| 国产午夜无码视频免费网站|