📄 jembossserver.java
字号:
} dout.close(); } catch (IOException ioe) {} RunEmbossApplication2 rea = new RunEmbossApplication2(embossCommand, envp,new File(project)); result.add("cmd"); result.add(appl + " " + rest); result.add("msg"); result.add(msg); result.add("status"); result.add("0"); if(options.toLowerCase().indexOf("interactive") > -1) { String stdout = ""; try { rea.getProcess().waitFor(); stdout = rea.getProcessStdout(); } catch(InterruptedException iexp){} if(!stdout.equals("")) { result.add("stdout"); result.add(stdout); } createFinishedFile(project); } else //batch or background { JembossThread jt = new JembossThread(rea,project); jt.start();// if(jt.isAlive())// System.out.println("THREAD IS ALIVE!"); result.add("job_submitted"); result.add("Job " + projectDir.getName() + "submitted."); result.add("jobid"); result.add(projectDir.getName()); result.add("description"); result.add(descript+ls+"Application pending"+ls); }//get the output files result = loadFilesContent(projectDir,project,result,inFiles); result = loadPNGContent(projectDir,project,result); return result; } /** * * Creates a file named "finished" in the project directory, * that contains a time stamp. * @param project project directory name * */ private void createFinishedFile(String project) { File finished = new File(new String(project + fs + ".finished")); try { PrintWriter fout = new PrintWriter(new FileWriter(finished)); fout.println((new Date()).toString()); fout.close(); } catch (IOException ioe) {} } /** * * Returns the results for a saved project. * @param project project directory name * @param cl unused if showing all results otherwise * this is the name of the file to display * @param userName username * @return saved results files * */ public Vector show_saved_results(String project, String cl, String userName) { Vector ssr = new Vector(); tmproot = tmproot.concat(userName+fs); ssr = show_saved_results(project,cl); return ssr; } /** * * Returns the results for a saved project. * @param project project directory name * @param cl unused if showing all results otherwise * this is the name of the file to display * @return saved results files * */ public Vector show_saved_results(String project, String cl) { Vector ssr = new Vector(); project = tmproot.concat(project); File projectDir = new File(project); if(cl.equals("")) { ssr = loadFilesContent(projectDir,project,ssr,null); ssr = loadPNGContent(projectDir,project,ssr); } else { try { String fc = ""; String line; File fn = new File(project + fs + cl); if(fn.exists()) { BufferedReader in = new BufferedReader(new FileReader(project + fs + cl)); while((line = in.readLine()) != null) fc = fc.concat(line + "\n"); } ssr.add(cl); ssr.add(fc); } catch (IOException ioe){} } ssr.add("status"); ssr.add("0"); ssr.add("msg"); ssr.add("OK"); return ssr; } /** * * Save a file to a project directory on the server. * @param project project directory to save file in * @param filename filename * @param notes text to write to file * @param userName username * @return message * */ public Vector save_project_file(String project, String filename, String notes, String userName) { return save_project_file(userName+ fs +project, filename, notes); } /** * * Save a file to a project directory on the server. * @param project project directory to save file in * @param filename filename * @param notes text to write to file * @param userName username * @return message * */ public Vector save_project_file(String project, String filename, String notes) { Vector v = new Vector(); String msg = "OK"; String fn = tmproot + fs + project + fs + filename; File f = new File(fn); try { if(!f.exists()) f.createNewFile(); FileOutputStream out = new FileOutputStream(f); out.write(notes.getBytes()); out.close(); } catch(IOException ioe) { msg = new String("Error making input file"); } v.add("status"); v.add("0"); v.add("msg"); v.add(msg); return v; } /** * * Deletes a projects saved results. * @param project project directory name * @param cl unused * @param userName username * @return message * */ public Vector delete_saved_results(String project, String cl, String userName) { Vector dsr = new Vector(); tmproot = tmproot.concat(userName+fs); dsr = delete_saved_results(project,cl); return dsr; } /** * * Deletes a projects saved results. * @param project project directory name * @param cl unused * @return message * */ public Vector delete_saved_results(String project, String cl) { Vector dsr = new Vector(); StringTokenizer st = new StringTokenizer(project,"\n"); while(st.hasMoreTokens()) { String proj = tmproot.concat(fs+st.nextToken()); File projectDir = new File(proj); File resFiles[] = projectDir.listFiles(); for(int i=0;i<resFiles.length;i++) resFiles[i].delete(); projectDir.delete(); } dsr.add("status"); dsr.add("0"); dsr.add("msg"); dsr.add("Results deleted successfully."); return dsr; } /** * * List of the saved results on the server. * @param userName username * @return list of the saved results. * */ public Vector list_saved_results(String userName) { Vector lsr = new Vector(); tmproot = tmproot.concat(userName+fs); tmprootDir = new File(tmproot); lsr = list_saved_results(); return lsr; } /** * * List of the saved results on the server. * @return list of the saved results. * */ public Vector list_saved_results() { Vector lsr = new Vector(); lsr.add("status"); lsr.add("0"); lsr.add("msg"); lsr.add("OK"); String resFiles[] = tmprootDir.list(new FilenameFilter() { public boolean accept(File cwd, String name) { return !name.startsWith("."); }; }); String list = ""; for(int i=0;i<resFiles.length;i++) { String line = new String(""); String fc = new String(""); try { BufferedReader in = new BufferedReader(new FileReader(tmproot + fs + resFiles[i] + fs + ".desc")); while((line = in.readLine()) != null) fc = fc.concat(line + "\n"); lsr.add(resFiles[i]); lsr.add(fc); list = list.concat(resFiles[i] + "\n"); } catch (IOException ioe) { System.out.println("IOException in list_saved_results " +tmproot + fs + resFiles[i] + fs + ".desc"); } } lsr.add("list"); lsr.add(list); return lsr; } /** * * Reads in files from EMBOSS output * @param projectDir project directory * @param project project name * @param result results * @param inFiles input files * @return result * */ private Vector loadFilesContent(File projectDir, String project, Vector result, Hashtable inFiles) { String outFiles[] = projectDir.list(new FilenameFilter() { public boolean accept(File cwd, String name) { return (!name.startsWith(".") && !name.endsWith(".png")); }; }); for(int i=0;i<outFiles.length;i++) { String line = new String(""); String fc = new String(""); String key = new String(outFiles[i]); if(inFiles != null) { if(!inFiles.containsKey(key)) // leave out input files { try { BufferedReader in = new BufferedReader(new FileReader(project + fs + outFiles[i])); while((line = in.readLine()) != null) fc = fc.concat(line + "\n"); } catch (IOException ioe){} } } else { try { BufferedReader in = new BufferedReader(new FileReader(project + fs + outFiles[i])); while((line = in.readLine()) != null) fc = fc.concat(line + "\n"); } catch (IOException ioe){} } if(!fc.equals("")) { result.add(key); result.add(fc); } } return result; } /** * * Reads in png files from EMBOSS output * @param projectDir project directory * @param project project name * @param result results * @return result * */ private Vector loadPNGContent(File projectDir, String project, Vector result) { String pngFiles[] = projectDir.list(new FilenameFilter() { public boolean accept(File cwd, String name) { if( name.endsWith(".png") || name.endsWith(".dat") ) return true; return false; }; }); for(int i=0;i<pngFiles.length;i++) { String key = new String(pngFiles[i]); DataInputStream dis = null; FileInputStream fis = null; int nby = 0; byte data[] = readByteFile(project + fs + pngFiles[i]); if(data != null) { result.add(key); result.add(data); } } return result; } /** * * Read a file into a byte array. * @param filename file name * @return byte[] contents of file * */ protected static byte[] readByteFile(String filename) { File fn = new File(filename); byte[] b = null; try { long s = fn.length(); if(s == 0) return b; b = new byte[(int)s]; FileInputStream fi = new FileInputStream(fn); fi.read(b); fi.close(); } catch (IOException ioe) { System.out.println("Cannot read file: " + filename); } return b; } /** * * Used to provide information on the batch/background * processes. * @param prog program * @param opt options * @param resToQuery results to query * @param userName username * */ public Vector update_result_status(String prog, String opt, Vector resToQuery,String userName) { return update_result_status(prog,opt,getHashtable(resToQuery), userName); } /** * * Used to provide information on the batch/background * processes. * @param prog program * @param opt options * @param resToQuery results to query * @param userName username * */ public Vector update_result_status(String prog, String opt, Hashtable resToQuery,String userName) { tmproot = tmproot.concat(userName+fs); return update_result_status(prog, opt, resToQuery); } /** * * Used to provide information on the batch/background * processes. * @param prog program * @param opt options * @param resToQuery results to query * */ public Vector update_result_status(String prog, String opt, Hashtable resToQuery) { Vector vans = new Vector(); Enumeration enumRes = resToQuery.keys(); while (enumRes.hasMoreElements()) { String thiskey = (String)enumRes.nextElement().toString(); String thiselm = (String)resToQuery.get(thiskey);// System.out.println("KEY : "+thiskey+" ELEMENT: "+thiselm); File f = new File(tmproot+fs+thiskey+fs+".finished"); if(f.exists()) { vans.add(thiskey); vans.add("complete"); String fc = ""; try { String line; BufferedReader in = new BufferedReader(new FileReader(tmproot+ fs+thiskey+fs+".desc")); while((line = in.readLine()) != null) fc = fc.concat(line + "\n"); } catch (IOException ioe) { fc = "Error in reading information file"; } vans.add(thiskey+"-description"); vans.add(fc); } else { vans.add(thiskey); vans.add("pending"); } } return vans; } /** * * Convert contents from a Vector to a Hashtable * @param v Vector * */ private Hashtable getHashtable(Vector v) { Hashtable h = new Hashtable(); for(Enumeration e = v.elements() ; e.hasMoreElements() ;) { String s = (String)e.nextElement(); h.put(s,e.nextElement()); } return h; } public final Object clone() throws java.lang.CloneNotSupportedException { throw new java.lang.CloneNotSupportedException(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -