java - How can I optimize this String search/replace method? -


i implementing own web server. following method searches server side includes , builds html page appropriately.

public string getssi(string content) throws ioexception {

    string beginstring = "<!--#include virtual=\"";     string endstring = "\"-->";      int beginindex = content.indexof(beginstring);     while (beginindex != -1) {         int endindex = content.indexof(endstring, beginindex);         string includepath = content.substring(beginindex+beginstring.length(), endindex);          file includefile = new file(base_dir+includepath);         byte[] bytes = new byte[(int) includefile.length()];         fileinputstream in = new fileinputstream(includefile);             in.read(bytes);         in.close();          string includecontent = new string(bytes);         includecontent = getssi(includecontent);          content = content.replaceall(beginstring+includepath+endstring, includecontent);          beginindex = content.indexof(beginstring);     }      return content; } 

i know stringbuilder faster string, can optimize this? original data read byte array , converted string, @ point passed method, , output converted byte array , sent client.

i don't know how significant of impact have, instead of reading byte array , and converting string, can use ioutils tostring(inputstream) method read directly string. likewise, can write string directly outputstream.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -