Files
Brainstorm/TripleReflectionTest/src/com/de22/foundation/trt/Test.java

173 lines
4.7 KiB
Java
Raw Normal View History

2014-05-30 10:31:51 -07:00
package com.de22.foundation.trt;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.common.debug.Debug;
import com.common.io.StreamSupport;
import com.common.util.LiteList;
import com.foundation.util.xml.DocumentBuilder;
import com.foundation.util.xml.IDocument;
import com.foundation.util.xml.INode;
public class Test {
private static final int MAX_COUNT = 10000;
private static void writeVeryLargeTestFile() {
try {
File f = new File("c:/temp/test_data.bin");
FileOutputStream fout = new FileOutputStream(f);
BufferedOutputStream bout = new BufferedOutputStream(fout, 1000);
for(int count = 0; count < MAX_COUNT; count++) {
for(int index = 0; index < 256; index++) {
bout.write(index);
}//for//
// if(count % 100 == 0) {
// bout.flush();
// }//if//
}//for//
bout.flush();
bout.close();
fout.close();
}//try//
catch(Throwable e) {
Debug.log(e);
}//catch//
}//writeVeryLargeTestFile()//
private static void checkVeryLargeTestFile() {
try {
File f = new File("c:/temp/test_data.bin");
FileInputStream fin = new FileInputStream(f);
BufferedInputStream bin = new BufferedInputStream(fin, 1000);
for(int count = 0; count < MAX_COUNT; count++) {
for(int index = 0; index < 256; index++) {
int next = bin.read();
if(index != next) {
Debug.log("Check failed at position: " + ((count + 1) * index) + "; Expected " + index + " and received " + next);
fin.close();
return;
}//if//
}//for//
}//for//
Debug.log("Check success.");
fin.close();
}//try//
catch(Throwable e) {
Debug.log(e);
}//catch//
}//checkVeryLargeTestFile()//
/**
* Detects and removes gaps in the end note numbering.
* @param doc
*/
public static void fixEndNoteNumbering(IDocument doc) {
LiteList list = new LiteList(10, 200);
/*
doc.findNodes("pages", list, true);
if(list.getSize() == 1) {
INode endNotesNode = (INode) list.get(0);
list.removeAll();
endNotesNode.findNodes("page", list);
for(int index = 0; index < list.getSize(); index++) {
INode next = (INode) list.get(index);
if(next.hasAttribute("id")) {
next.getAttribute("id").setValue(Integer.toString(index + 1));
}//if//
else {
next.addAttribute("id", Integer.toString(index + 1));
}//else//
String text = next.getAttributeValue("text");
int periodIndex = text.indexOf('.');
text = (index + 1) + text.substring(periodIndex);
next.getAttribute("text").setValue(text);
}//for//
}//if//
*/
doc.findNodes("end-notes", list, true);
if(list.getSize() == 1) {
INode endNotesNode = (INode) list.get(0);
list.removeAll();
endNotesNode.findNodes("note", list);
for(int index = 0; index < list.getSize(); index++) {
INode next = (INode) list.get(index);
if(next.hasAttribute("id")) {
next.getAttribute("id").setValue(Integer.toString(index + 1));
}//if//
else {
next.addAttribute("id", Integer.toString(index + 1));
}//else//
String text = next.getAttributeValue("text");
int periodIndex = text.indexOf('.');
text = (index + 1) + text.substring(periodIndex);
next.getAttribute("text").setValue(text);
}//for//
}//if//
}//fixEndNoteNumbering()//
/**
* @param args
*/
public static void main(String[] args) {
// File x = new File("\\\\misys\\images\\Allscripts\\Store\\201049\\A0248638");
//
// System.out.println(x.getAbsolutePath().replace('\\', '/'));
// System.out.println(x.getParent());
// System.out.println(x.getName());
//writeVeryLargeTestFile();
//checkVeryLargeTestFile();
//System.exit(0);
try {
File f = new File("c:/Users/Administrator/Desktop/Kobel/Kobel.xml");
File f2 = new File("c:/Users/Administrator/Desktop/Kobel/Kobel2.xml");
DocumentBuilder builder = new DocumentBuilder();
//builder.setIgnoreTextWhitespace(Boolean.FALSE);
builder.decodeContent(false);
IDocument doc = builder.readDocument(StreamSupport.readText(f, "UTF8"));
fixEndNoteNumbering(doc);
String out = builder.writeDocument(doc, "UTF8", false);
StreamSupport.writeText(out, f2, "UTF8");
}//try//
catch(Throwable e) {
Debug.log(e);
}
/*
try {
File f = new File("c:/Users/Administrator/Desktop/Kobel 2.txt");
File f2 = new File("c:/Users/Administrator/Desktop/Kobel 2.xml");
DocumentBuilder builder = new DocumentBuilder();
IDocument doc = builder.readDocument(StreamSupport.readText(f, "UTF8"));
String out = builder.writeDocument(doc, "UTF8", false);
StreamSupport.writeText(out, f2, "UTF8");
}//try//
catch(Throwable e) {
Debug.log(e);
}
*/
}
}