我正在为我的应用程序构建一个帮助系统。帮助系统由带有工具栏树和浏览器窗格的外壳组成。树将文件加载到节点中,单击该链接时会在浏览器中打开一个 HTML 文件。当单击工具栏上的按钮时,调用 text = browser.getText() 并通过缓冲区将文本加载到 HTML 标签剥离器,该标签剥离器被收集在三个数组中,然后解析给 styledtext 编辑器的样式创建器。
- 缓冲区集成在标签阅读器类中,我想创建一个全局类以在应用程序中的任何地方需要时使用它,但在解析到 buffer.class 时遇到常量字符字符串等问题
该数组由三个数组组成,其中填充了阅读器找到的标签,我希望 add 方法在全局范围内工作,以便在需要的应用程序中使用它。
我可以使用 List list = new ArrayList(); 但为了便于开销和更好的理解,我尝试只使用数组。
public class XMLHtmlTagReader { private static char startchar = '<'; private static char endchar= '>'; private static char[] closingchar ={'<','/'}; private static String startTag; private static String endTag; private static String tagValue; static String[] starttaglist = new String[]{"first","second","third","fourth"}; static String[]tagvaluelist;// = new String[1]; static String[] endtaglist;// = new String[1]; int tagcount=0; static char newchar; static char newchar1; static int i=0; static int startcharint = -1; static int endcharint = -1; static int closingcharint = -1; static int level=0; static int elm=0; boolean closing = false; static Object store[] = new Object[26]; Object[][][] megastore = new Object[50][50][50]; int storeCounter = 0; int count=-1; int Wmstore=0,WstoreCounter=0,Wv=0; int Rmstore=0; static int RstoreCounter=0; static int Rv=0; static int Rtmp; int Omstore=0; static int OstoreCounter=0; static int Ov=0; int mstore=0; long time = 3087; public static void main(String[] args) { XMLHtmlTagReader run=new XMLHtmlTagReader(); } XMLHtmlTagReader(){ long memstart = (Runtime.getRuntime().totalMemory()- Runtime.getRuntime().freeMemory()); System.out.println("Memory at start:"+memstart); long startTime = System.nanoTime(); getStream("<html><title>hallo de titel ...</title><p>Dit is de text.</p><b>dikke text</b></html>"); //for(int t=0;t<100000;t++){new com.pim.Buffer(endchar);} long estimatedTime = (System.nanoTime() - startTime); //(System.currentTimeMillis() - startTime); //(System.nanoTime() - startTime)/1000000; //long calc = (estimatedTime/time)*100; System.out.println(memstart+"memstart "+"execution time = "+estimatedTime+" is % sneller/langzamer = "+(estimatedTime/time)*100+"Memory = "+(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())); bufferWrite('E'); } public static String getStream(String input) { while(input != null){ i++; try { newchar = input.charAt(i); } catch (java.lang.StringIndexOutOfBoundsException exception){ break; } if(newchar!=closingchar[1]&&input.charAt(i-1)==startchar){ startcharint=i; level++; } if(newchar==closingchar[1]&&input.charAt(i-1)==startchar) { closingcharint=i; tagValue = input.substring(endcharint+1,closingcharint-1); if(tagValue!=null){log("valuetag ["+tagValue+"]->"+endcharint+" ->"+closingcharint);} } if(newchar==endchar) { endcharint=i; if(startcharint>=0){ startTag = input.substring(startcharint-1,endcharint+1); log("starttag "+startTag); } else {startTag=" no Start tag found "; } if(closingcharint>0){ endTag = input.substring(closingcharint-1,endcharint+1); level--; log("endtag->"+endTag); log("level->"+level); } else { endTag=" no end tag found "; } closingcharint=0; startcharint=-1; } } startchar = 0; endchar = 0; closingchar = null; newchar = 0; newchar1 = 0; return input; } private static void addElementToArray(String string){ String[] tmpArray; int length = starttaglist.length; tmpArray = new String[length+1]; System.arraycopy(starttaglist, 0,tmpArray , 0, length); tmpArray[length] = new String(string); starttaglist = null; starttaglist = new String[length+1]; System.arraycopy(tmpArray, 0,starttaglist , 0, length+1); for(String tmp:starttaglist){ System.out.println("Elements in Array "+tmp); } tmpArray = null; } public static String[] getStartTag(){ return starttaglist; } public static String[] getTagValue(){ for(String tmp:tagvaluelist){ } return tagvaluelist; } public static String[] getEndTag(){ return endtaglist; } static Object bufferWrite(char value){ store[OstoreCounter] = new Object(); store[OstoreCounter] = value; //System.out.println("bufferWrite=["+OstoreCounter+"] storeValue=["+store[OstoreCounter]+"] Ov="+Ov); if(Ov==30&&store[RstoreCounter] == null){ Rtmp=Ov; Ov=0; } if(Ov==40){ OstoreCounter++; Ov=0; } Ov++; char tmp = (char) bufferRead(); return tmp; } static Object bufferRead(){ Object tmp = store[RstoreCounter]; //System.out.println("bufferRead=["+RstoreCounter+"] storeValue= ["+store[RstoreCounter]+"] Rv="+Rv); store[RstoreCounter] = null; if(Rv==Rtmp){ Rv=0; } if(Rv==40){ RstoreCounter++; Rv=0; } //System.out.println("bufferRead reads till end of int"+Rtmp); Rv++; return tmp; } static void log(String txt){ System.out.println(txt); } }