⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x_tar.java

📁 learning java的源代码。书中每个实例都有相关的代码example。
💻 JAVA
字号:
//file: x_tar.javapackage learningjava.contenthandlers.application;import java.net.*;import java.io.*;import java.util.Date;public class x_tar extends ContentHandler {  static int    RECORDLEN = 512,    NAMEOFF = 0, NAMELEN = 100,    SIZEOFF = 124, SIZELEN = 12,    MTIMEOFF = 136, MTIMELEN = 12;  public Object getContent(URLConnection uc) throws IOException {    InputStream is = uc.getInputStream(  );    StringBuffer output =        new StringBuffer( "Tape Archive Listing:\n\n" );    byte [] header = new byte[RECORDLEN];    int count = 0;    while ( (is.read(header) == RECORDLEN)             && (header[NAMEOFF] != 0) ) {      String name =           new String(header, NAMEOFF, NAMELEN, "8859_1"). trim(  );      String s =           new String(header, SIZEOFF, SIZELEN, "8859_1").trim(  );      int size = Integer.parseInt(s, 8);      s = new String(header, MTIMEOFF, MTIMELEN, "8859_1").trim(  );      long l = Integer.parseInt(s, 8);      Date mtime = new Date( l*1000 );      output.append( size + " " + mtime + " " + name + "\n" );      count += is.skip( size ) + RECORDLEN;      if ( count % RECORDLEN != 0 )        count += is.skip ( RECORDLEN - count % RECORDLEN);    }    if ( count == 0 )      output.append("Not a valid TAR file\n");    return( output.toString(  ) );  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -