if(!s。startsWith(packMarker))
Pr。error(〃Can"t find 〃 + packMarker
+ 〃 in 〃 + s);
s = s。substring(
packMarker。length())。trim();
dirname = s。substring(0; s。indexOf("#"));
filename = s。substring(s。indexOf("#") + 1);
dirname = dirname。replace(
oldsep。charAt(0); filesep。charAt(0));
filename = filename。replace(
oldsep。charAt(0); filesep。charAt(0));
System。out。println(〃l isting: 〃 + dirname
+ filesep + filename);
while((s = pFile。readLine()) != null) {
// Watch for end of code listing:
if(s。startsWith(endMarker) ||
s。startsWith(endMarker2)) {
contents += s;
626
…………………………………………………………Page 628……………………………………………………………
break;
}
contents += s + eol;
}
} catch(IOException e) {
System。err。println(〃Error reading line〃);
}
}
public boolean hasFile() {
return filename != null;
}
public String directory() { return dirname; }
public String filename() { return filename; }
public String contents() { return contents; }
// To write to a packed file:
public void writePacked(DataOutputStream out) {
try {
out。writeBytes(
packMarker + dirname + 〃#〃
+ filename + eol);
out。writeBytes(contents);
} catch(IOException e) {
Pr。error(〃writing 〃 + dirname +
filesep + filename);
}
}
// To generate the actual file:
public void writeFile(String rootpath) {
File path = new File(rootpath; dirname);
path。mkdirs();
PrintWriter p =
IO。psOpen(new File(path; filename));
p。print(contents);
IO。close(p);
}
}
class DirMap {
private Hashtable t = new Hashtable();
private String rootpath;
DirMap() {
rootpath = System。getProperty(〃user。dir〃);
}
DirMap(String alternateDir) {
rootpath = alternateDir;
}
public void add(SourceCodeFile f){
String path = f。directory();
if(!t。containsKey(path))
t。put(path; new Vector());
((Vector)t。get(path))。addElement(f);
}
627
…………………………………………………………Page 629……………………………………………………………
public void writePackedFile(String fname) {
DataOutputStream packed = IO。dosOpen(fname);
try {
packed。writeBytes(〃###Old Separator:〃 +
SourceCodeFile。filesep + 〃###n〃);
} catch(IOException e) {
Pr。error(〃Writing separator to 〃 + fname);
}
Enumeration e = t。keys();
while(e。hasMoreElements()) {
String dir = (String)e。nextElement();
System。out。println(
〃Writing directory 〃 + dir);
Vector v = (Vector)t。get(dir);
for(int i = 0; i 《 v。size(); i++) {
SourceCodeFile f =
(SourceCodeFile)v。elementAt(i);
f。writePacked(packed);
}
}
IO。close(packed);
}
// Write all the files in their directories:
public void write() {
Enumeration e = t。keys();
while(e。hasMoreElements()) {
String dir = (String)e。nextElement();
Vector v = (Vector)t。get(dir);
for(int i = 0; i 《 v。size(); i++) {
SourceCodeFile f =
(SourceCodeFile)v。elementAt(i);
f。writeFile(rootpath);
}
// Add file indicating file quantity
// written to this directory as a check:
IO。close(IO。dosOpen(
new File(new File(rootpath; dir);
Integer。toString(v。size())+〃。files〃)));
}
}
}
public class CodePackager {
private static final String usageString =
〃usage: java CodePackager packedFileName〃 +
〃nExtracts source code files from packed n〃 +
〃version of Tjava。doc sources into 〃 +
〃directories off current directory n〃 +
〃java CodePackager packedFileName newDirn〃 +
〃Extracts into directories off newDirn〃 +
〃java CodePackager …p source。txt packedFile〃 +
〃nCreates packed version of source files〃 +
628
…………………………………………………………Page 630……………………………………………………………
〃nfrom text version of Tjava。doc〃;
private static void usage() {
System。err。println(usageString);
System。exit(1);
}
public static void main(String'' args) {
if(args。length == 0) usage();
if(args'0'。equals(〃…p〃)) {
if(args。length != 3)
usage();
createPackedFile(args);
}
else {
if(args。length 》 2)
usage();
extractPackedFile(args);
}
}
private static String currentLine;
private static BufferedReader in;
private static DirMap dm;
private static void
createPackedFile(String'' args) {
dm = new DirMap();
in = IO。disOpen(args'1');
try {
while((currentLine = in。readLine())
!= null) {
if(currentLine。startsWith(
SourceCodeFile。startMarker)) {
dm。add(new SourceCodeFile(
currentLine; in));
}
else if(currentLine。startsWith(
SourceCodeFile。endMarker))
Pr。error(〃file has no start marker〃);
// Else ignore the input line
}
} catch(IOException e) {
Pr。error(〃Error reading 〃 + args'1');
}
IO。close(in);
dm。writePackedFile(args'2');
}
private static void
extractPackedFile(
小说推荐
- 软件工程实践者的思想(PDF格式)
- -Page 1-大 道 至 简—软件工程实践者的思想周爱民(Aimingoo 著-Page 2-序2004 年 11 月初爱民(Aimingoo)第一次把他的书稿给我,我翻看了一下,第一反应讲的是感想。这不错,在技
- 最新章:第26章
- 深入浅出MFC第2版(PDF格式)
- -Page 1-Page 2-山高月小山高月小 水落石出水落石出山高月小山高月小 水落石出水落石出-Page 3-深入淺出MFC(第版 使用Visual C 5.0 MFC 4.2)Dissecting MFC(Second Edition Using Visual C 5.0 MFC 4.2)侯俊
- 最新章:第309章
- VB2008从入门到精通(PDF格式英文版)
- -Page 1(R)The eXperT’s Voice inBeginningVB 2008From Novice to ProfessionalChristian Gross-Page 2-Page 3-Beginning VB 2008From Novice to Professional■C
- 最新章:第214章
- C语言游戏编程从入门到精通(PDF格式)
- -Page 1-Page 2-Page 3-Page 4-Page 5-Page 6-Page 7-Page 8-Page 9-Page 10-Page 11-Page 12-Page 13-Page 14
- 最新章:第4章
- JMS简明教程(PDF格式)
- -Page 1-JMS1.1规范中文版卫建军2007‐11‐22-Page 2
- 最新章:第28章
- C语言实例教程(PDF格式)
- -Page 1-前 言Visual C+是开发运行于Windows 95和Windows NT环境下的Win32应用程序的可视化编程工具中最重要的成员之一,它为软件开发人员提供了完整的编辑、编译和调试工具和建立于Win32 API(ApplicationProgramming Interface)基
- 最新章:第143章
- 神祗之眼 (正式版)第7卷(全文完)作者:百里芜虚
- 第五十一章离12月25日的圣诞节还有两天,纽约已经换上了节日的盛装,几天前的一场大雪令整个城市一片银白。人们笑逐颜开,都纷纷开始为节日做准备,商家为了在节日打开销路纷纷推出各种优惠促销手段,纽约的大街小巷全都这样热闹。依沙那被老婆打发出来买过节要用的杂货,而女儿则和凯妮一起到百货商场去买衣服去了。对
- 最新章:第23章
- SQL语言艺术(PDF格式)
- -Page 1-SQLSSQQLL语言艺术内容介绍本书分为12章,每一章包含许多原则或准则,并通过举例的方式对原则进行解释说明。这些例子大多来自于实际案例,对九种SQL经典查询场景以及其性能影响讨论,非常便于实践,为你数据库应用维护人员阅读。资深 SQL 专家 Stéphane Faroult倾力打
- 最新章:第27章
- php程序设计简明教程(DOC格式)
- -Page 1-PHP 程序设计简明教程PHP 讲义 第 1 页 共 90 页-Page 2-目录序 4第一章 PHP 简介 6
- 最新章:第31章