String javap(String... args) { StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); // sun.tools.javap.Main.entry(args); int rc = com.sun.tools.javap.Main.run(args, out); if (rc != (args.length == 0 ? 2 : 0)) throw new Error("javap failed. rc=" + rc); out.close(); return sw.toString(); }
public TestCRFPipe(String trainingFilename) throws IOException { ArrayList<Pipe> pipes = new ArrayList<Pipe>(); PrintWriter out = new PrintWriter("test.out"); int[][] conjunctions = new int[3][]; conjunctions[0] = new int[] {-1}; conjunctions[1] = new int[] {1}; conjunctions[2] = new int[] {-2, -1}; pipes.add(new SimpleTaggerSentence2TokenSequence()); // pipes.add(new FeaturesInWindow("PREV-", -1, 1)); // pipes.add(new FeaturesInWindow("NEXT-", 1, 2)); pipes.add(new OffsetConjunctions(conjunctions)); pipes.add(new TokenTextCharSuffix("C1=", 1)); pipes.add(new TokenTextCharSuffix("C2=", 2)); pipes.add(new TokenTextCharSuffix("C3=", 3)); pipes.add(new RegexMatches("CAPITALIZED", Pattern.compile("^\\p{Lu}.*"))); pipes.add(new RegexMatches("STARTSNUMBER", Pattern.compile("^[0-9].*"))); pipes.add(new RegexMatches("HYPHENATED", Pattern.compile(".*\\-.*"))); pipes.add(new RegexMatches("DOLLARSIGN", Pattern.compile("\\$.*"))); pipes.add(new TokenFirstPosition("FIRSTTOKEN")); pipes.add(new TokenSequence2FeatureVectorSequence()); pipes.add(new SequencePrintingPipe(out)); Pipe pipe = new SerialPipes(pipes); InstanceList trainingInstances = new InstanceList(pipe); trainingInstances.addThruPipe( new LineGroupIterator( new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(trainingFilename)))), Pattern.compile("^\\s*$"), true)); out.close(); }
/** * This method handles PUT requests from the client. PUT requests will come from the applet * portion of this application and are the way that images and other files can be posted to the * server. * * @param request the HTTP request object * @param response the HTTP response object * @exception ServletException * @exception IOException */ public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); /* * The Scan applet will zip all the files together to create a * faster upload and to use just one server connection. */ ZipInputStream in = new ZipInputStream(request.getInputStream()); /* * This will write all the files to a directory on the server. */ try { try { File file = new File("scan"); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); String fileSize = null; while (true) { ZipEntry entry = in.getNextEntry(); if (entry == null) { break; } File f = File.createTempFile("translate", entry.getName()); FileOutputStream out = new FileOutputStream(f); FileInputStream inStream = null; try { int read; byte[] buf = new byte[2024]; while ((read = in.read(buf)) > 0) { out.write(buf, 0, read); } out.close(); inStream = new FileInputStream(f); System.out.println(entry.getSize()); byte[] b = new byte[inStream.available()]; inStream.read(b); System.out.println(b.length); com.itextpdf.text.Image image1 = com.itextpdf.text.Image.getInstance(b); image1.scalePercent(30); image1.setCompressionLevel(9); document.add(image1); } finally { } } document.close(); // fileSize = CommonUtils.getFileSize(file); // DocumentStoreLogDAO documentStoreLogDAO = new DocumentStoreLogDAO(); // DocumentStoreLog documentStoreLog = null; // DocumentStoreLog documentStore = // (DocumentStoreLog)session.getAttribute(CommonConstants.DOCUMENT_STORE_LOG); // if(null != documentStore) { // documentStore.setFileSize(fileSize); // } // Transaction tx = documentStoreLogDAO.getSession().getTransaction(); // tx.begin(); // documentStoreLogDAO.save(documentStore); // tx.commit(); } catch (ZipException ze) { /* * We want to catch each sip exception separately because * there is a possibility that we can read more files from * the archive even if one of them is corrupted. */ ze.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } finally { in.close(); } /* * Now that we have finished uploading the files * we will send a reponse to the server indicating * our success. */ response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); out.println("<html><head><title>ImageSrv</title></head></html>"); out.flush(); out.close(); response.setStatus(HttpServletResponse.SC_OK); }