/** * Parse this pipeline and run it * * @return true if no error during processing * @throws ParseException */ public static void runPipeline(File scriptFile, List<String> cliArgs) throws IOException, UIMAException, ParseException { if (!scriptFile.exists()) { throw new IOException("Script file does not exist (" + scriptFile.getAbsolutePath() + ")"); } LOG.info( "Parsing pipeline script at '{}'", scriptFile.getAbsolutePath() + " \n with CLI parameters: " + join(cliArgs, ", ")); Pipeline pipeline = null; try { pipeline = PipelineScriptParser.parse(scriptFile, cliArgs); } catch (ParseException e) { throw new ParseException( "\nERROR parsing '" + scriptFile.getName() + "'\n" + e.getMessage() + "\n(see the README.txt for the pipeline script format)", e.getErrorOffset()); } LOG.info("Successfully parsed pipeline script, now starting pipeline..."); LOG.info("*************************************************************"); pipeline.run(); // will be printed if no exception. // used in pipeline tests, do not change System.out.println(OK_MESSAGE); }
private static SQLDeploymentDescriptor[] getDeploymentDescriptors(int jarId) throws SQLException { ResultSet rs = null; PreparedStatement stmt = SQLUtils.getDefaultConnection() .prepareStatement( "SELECT e.entryImage" + " FROM sqlj.jar_descriptor d INNER JOIN sqlj.jar_entry e" + " ON d.entryId = e.entryId" + " WHERE d.jarId = ?" + " ORDER BY d.ordinal"); try { stmt.setInt(1, jarId); rs = stmt.executeQuery(); ArrayList<SQLDeploymentDescriptor> sdds = new ArrayList<SQLDeploymentDescriptor>(); while (rs.next()) { byte[] bytes = rs.getBytes(1); // According to the SQLJ standard, this entry must be // UTF8 encoded. // sdds.add(new SQLDeploymentDescriptor(new String(bytes, "UTF8"), "postgresql")); } return sdds.toArray(new SQLDeploymentDescriptor[sdds.size()]); } catch (UnsupportedEncodingException e) { // Excuse me? No UTF8 encoding? // throw new SQLException("JVM does not support UTF8!!"); } catch (ParseException e) { throw new SQLException(e.getMessage() + " at " + e.getErrorOffset()); } finally { SQLUtils.close(rs); SQLUtils.close(stmt); } }
@Override public void afterTextChanged(Editable s) { String mask = mMask; String value = s.toString(); if (value.equals(mResult)) return; try { /* prepare the formatter*/ MaskedFormatter formatter = new MaskedFormatter(mask); formatter.setValueContainsLiteralCharacters(false); formatter.setPlaceholderCharacter( (char) 1); /* get a string with applied mask and placeholder chars*/ value = formatter.valueToString(value); try { /* find first placeholder*/ value = value.substring(0, value.indexOf((char) 1)); /*process a mask char*/ if (value.charAt(value.length() - 1) == mask.charAt(value.length() - 1)) value = value.substring(0, value.length() - 1); } catch (Exception e) { } mResult = value; s.replace(0, s.length(), value); } catch (ParseException e) { // the entered value does not match a mask int offset = e.getErrorOffset(); value = removeCharAt(value, offset); s.replace(0, s.length(), value); } }
// Formulas that should and should not fail. @Test public void test4() { Map<String, Integer> formulasToOffsets = new LinkedHashMap<String, Integer>(); // -1 means it should parse. formulasToOffsets.put("X X", 2); formulasToOffsets.put("b11 b11", 4); formulasToOffsets.put("X + Y ++", 7); formulasToOffsets.put("b1*X1 *+ b2 * X2 +", 17); formulasToOffsets.put("cos()", 0); formulasToOffsets.put("2..3 * X", 0); formulasToOffsets.put("+X1", -1); formulasToOffsets.put("-X1", -1); formulasToOffsets.put("A / B", -1); formulasToOffsets.put("b1*X1 +@**!! b2 * X2", 7); formulasToOffsets.put("X7", 0); List<String> otherNodes = new ArrayList<String>(); otherNodes.add("X7"); ExpressionParser parser = new ExpressionParser(otherNodes, ExpressionParser.RestrictionType.MAY_NOT_CONTAIN); for (String formula : formulasToOffsets.keySet()) { try { parser.parseExpression(formula); assertEquals(formulasToOffsets.get(formula).intValue(), -1); } catch (ParseException e) { int offset = e.getErrorOffset(); assertEquals(formulasToOffsets.get(formula).intValue(), offset); } } }
@Override public Object eval(ScriptContext context) throws ScriptException { try { return template.evaluate(); } catch (ParseException e) { throw new ScriptException(e.getMessage(), template.getName(), e.getErrorOffset()); } }
/** 日期解析-将<code>String</code>类型的日期解析为<code>Date</code>型 */ public static Date parse(String strDate, String pattern) throws ParseException { try { return getFormatter(pattern).parse(strDate); } catch (ParseException pe) { throw new ParseException( "Method parse in Class DateUtils err: parse strDate fail.", pe.getErrorOffset()); } }
@Test public void testOutOfOrderRange() { IdListParser parser = parserFor("13-12,14", null); try { parser.parse(); fail("An exception should have been thrown"); } catch (ParseException e) { assertEquals(4, e.getErrorOffset()); } }
@Test public void testIncorrectlyFormattedSeparator() { IdListParser parser = parserFor("12-13,14", null); try { parser.parse(); fail("An exception should have been thrown"); } catch (ParseException e) { assertEquals(5, e.getErrorOffset()); } }
/** Signals that an error has been reached unexpectedly while parsing. */ @ExceptionHandler(ParseException.class) public ResponseEntity<Map<String, Object>> handleParseException(ParseException error) { Map<String, Object> errorMap = new HashMap<String, Object>(); errorMap.put("hasErrors", "true"); errorMap.put("developerMessage", error.getMessage() + "at position " + error.getErrorOffset()); errorMap.put("userMessage", error.getMessage()); errorMap.put("moreInfo", error.getMessage()); errorMap.put("errorCode", HttpStatus.BAD_REQUEST); error.printStackTrace(); return new ResponseEntity<Map<String, Object>>(errorMap, HttpStatus.BAD_REQUEST); }
public Task(String name, String description, String date) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(ConfigReader.getInstance().getDateFormat()); this.name = name; this.description = description; try { this.date = sdf.parse(date); } catch (ParseException ex) { log.error("DateString didn't matched pattern: " + date, ex); throw new ParseException("DateString didn't matched pattern: " + date, ex.getErrorOffset()); } }
/* * @see org.argouml.uml.notation.NotationProvider#parse(java.lang.Object, java.lang.String) */ public void parse(Object modelElement, String text) { try { parseStateBody(modelElement, text); } catch (ParseException pe) { String msg = "statusmsg.bar.error.parsing.statebody"; Object[] args = { pe.getLocalizedMessage(), Integer.valueOf(pe.getErrorOffset()), }; ArgoEventPump.fireEvent( new ArgoHelpEvent( ArgoEventTypes.HELP_CHANGED, this, Translator.messageFormat(msg, args))); } }
/** * @see * org.argouml.uml.diagram.ui.FigNodeModelElement#textEdited(org.tigris.gef.presentation.FigText) */ protected void textEdited(FigText ft) throws PropertyVetoException { super.textEdited(ft); Object classifier = getOwner(); if (classifier == null) { return; } int i = new Vector(getAttributesFig().getFigs()).indexOf(ft); if (i != -1) { highlightedFigText = (CompartmentFigText) ft; highlightedFigText.setHighlighted(true); try { Object attribute = highlightedFigText.getOwner(); ParserDisplay.SINGLETON.parseAttributeFig( classifier, attribute, highlightedFigText.getText().trim()); ProjectBrowser.getInstance().getStatusBar().showStatus(""); } catch (ParseException pe) { String msg = "statusmsg.bar.error.parsing.attribute"; Object[] args = {pe.getLocalizedMessage(), new Integer(pe.getErrorOffset())}; ProjectBrowser.getInstance().getStatusBar().showStatus(Translator.messageFormat(msg, args)); } return; } i = new Vector(getOperationsFig().getFigs()).indexOf(ft); if (i != -1) { highlightedFigText = (CompartmentFigText) ft; highlightedFigText.setHighlighted(true); try { Object operation = highlightedFigText.getOwner(); ParserDisplay.SINGLETON.parseOperationFig( classifier, operation, highlightedFigText.getText().trim()); ProjectBrowser.getInstance().getStatusBar().showStatus(""); } catch (ParseException pe) { String msg = "statusmsg.bar.error.parsing.operation"; Object[] args = {pe.getLocalizedMessage(), new Integer(pe.getErrorOffset())}; ProjectBrowser.getInstance().getStatusBar().showStatus(Translator.messageFormat(msg, args)); } return; } }
public void testWrongArity() throws Exception { try { JavascriptCompiler.compile("tan()"); fail(); } catch (ParseException expected) { assertEquals( "Invalid expression 'tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage()); assertEquals(expected.getErrorOffset(), 0); } try { JavascriptCompiler.compile("tan(1, 1)"); fail(); } catch (ParseException expected) { assertTrue(expected.getMessage().contains("arguments for function call")); } try { JavascriptCompiler.compile(" tan()"); fail(); } catch (ParseException expected) { assertEquals( "Invalid expression ' tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage()); assertEquals(expected.getErrorOffset(), 1); } try { JavascriptCompiler.compile("1 + tan()"); fail(); } catch (ParseException expected) { assertEquals( "Invalid expression '1 + tan()': Expected (1) arguments for function call (tan), but found (0).", expected.getMessage()); assertEquals(expected.getErrorOffset(), 4); } }
private Date parseTagFallback(String tag) { // If we cannot extract timestamp from tag, it must be non-scheduled backup. We // just treat all manual backups as MIN_DATE, anyway they will be further ordered // by raw string value if the timestamps are equal. try { return ScheduledBackupTag.parseBackupTag(tag); } catch (ParseException e) { log.info( "Can't parse timestamp from the tag of non-scheduled backup({}, errorOffset is at {})", e.getMessage(), e.getErrorOffset()); return MIN_DATE; } }
@Override public void parse(Object modelElement, String text) { try { parseEnumerationLiteralFig( Model.getFacade().getEnumeration(modelElement), modelElement, text); } catch (ParseException pe) { String msg = "statusmsg.bar.error.parsing.enumeration-literal"; Object[] args = { pe.getLocalizedMessage(), Integer.valueOf(pe.getErrorOffset()), }; ArgoEventPump.fireEvent( new ArgoHelpEvent( ArgoEventTypes.HELP_CHANGED, this, Translator.messageFormat(msg, args))); } }
/** * 将字符串转换为日期 * * @param aMask * @param strDate * @return * @throws ParseException */ public static final Date convertStringToDate(String aMask, String strDate) throws ParseException { SimpleDateFormat sdf = null; Date date = null; sdf = new SimpleDateFormat(aMask); if (log.isDebugEnabled()) { log.debug("converting '" + strDate + "' to date with mask '" + aMask + "'"); } try { date = sdf.parse(strDate); } catch (ParseException ex) { throw new ParseException(ex.getMessage(), ex.getErrorOffset()); } return date; }
@Override public Date read(JsonParser parser) throws IOException, JsonReadException { JsonLocation l = parser.getCurrentLocation(); try { char[] buffer = parser.getTextCharacters(); int offset = parser.getTextOffset(); int length = parser.getTextLength(); Date d = parseDropbox8601Date(buffer, offset, length); parser.nextToken(); return d; } catch (JsonParseException ex) { throw JsonReadException.fromJackson(ex); } catch (java.text.ParseException ex) { throw new JsonReadException( "bad date: \"" + ex.getMessage() + " at offset " + ex.getErrorOffset(), l); } }
/** * This method generates a string representation of a date/time in the format you specify on input * * @param aMask the date pattern the string is in * @param strDate a string representation of a date * @return a converted Date object * @throws ParseException when String doesn't match the expected format * @see java.text.SimpleDateFormat */ public static Date convertStringToDate(String aMask, String strDate) throws ParseException { SimpleDateFormat df; Date date; df = new SimpleDateFormat(aMask); if (log.isDebugEnabled()) { log.debug("converting '" + strDate + "' to date with mask '" + aMask + "'"); } try { date = df.parse(strDate); } catch (ParseException pe) { // log.error("ParseException: " + pe); throw new ParseException(pe.getMessage(), pe.getErrorOffset()); } return (date); }
public void load(RandomAccessFile dataFile) throws RuntimeException, IOException, ParseException { try { if (dataFile.length() == 0) { return; } long currPtr = 0; long firstOffset = 0; long newOffset = 0; long nextOffset = 0; String keyFirst = ""; String keySecond = ""; String value; dataFile.seek(currPtr); keyFirst = getKeyFromFile(dataFile); newOffset = dataFile.readInt(); currPtr = dataFile.getFilePointer(); checkOffset(newOffset, currPtr, dataFile); firstOffset = newOffset; do { dataFile.seek(currPtr); if (currPtr < firstOffset) { keySecond = getKeyFromFile(dataFile); nextOffset = dataFile.readInt(); currPtr = dataFile.getFilePointer(); checkOffset(nextOffset, currPtr, dataFile); } else if (currPtr == firstOffset) { nextOffset = dataFile.length(); currPtr++; } if (nextOffset < newOffset) { IOException e1 = new IOException(); throw e1; } dataFile.seek(newOffset); value = getValueFromFile(nextOffset, dataFile); MyStoreable val; try { val = (MyStoreable) table.getProvider().deserialize(table, value); } catch (ParseException e) { throw new ParseException( filePath + " can't deserialize values from file " + e.getMessage(), e.getErrorOffset()); } data.put(keyFirst, val); // table.getHashMap().put(keyFirst, val);*/ keyFirst = keySecond; newOffset = nextOffset; } while (currPtr <= firstOffset); hasChanged = true; } catch (IOException e1) { throw new IOException(filePath + " can't read values from file", e1); } catch (OutOfMemoryError e2) { throw new RuntimeException(filePath + " can't read values from file: out of memory", e2); } }
/** * Performs some compilation job. * * @param defsFile */ public static void compile( String fileName, String job, int tailoredQCQs, String profilingFile, String priorCircuit, long seed, int statementBufferSize, boolean verbose, boolean bigconstraints, String defsFile) throws IOException { Function.functionSeedGenerator = new Random(seed); // boolean opt = job.contains("o"); String outFileName = new File(fileName).getName(); outFileName += "." + Optimizer.optimizationTarget.name(); String circuitFile = outFileName + ".circuit"; Statement computation = null; boolean outputConstants = false; AssignmentStatement.typeCheck = job.contains("t"); AssignmentStatement.allowBigConstraints = bigconstraints; DependencyProfile.printUpdates = verbose; boolean doProfile = job.contains("p"); if (doProfile) { DependencyProfile dp = new DependencyProfile(); dp.makeProfile(new File(fileName), new File(fileName + ".profile")); return; } Optimizer.setFirstPass(false); if (job.contains("c")) { // If profile is available, read it in. if (profilingFile != null) { File profile = new File(profilingFile); File priorCircuit_ = new File(priorCircuit); if (verbose) System.out.println("Optimizing previously compiled circuit " + priorCircuit); if (verbose) System.out.println("Using variable dependencies from profile " + profilingFile); computation = new CompiledStatement(profile, priorCircuit_); if (verbose) System.out.println("(Complete.)"); } else { Optimizer.setFirstPass(true); Program program = new Program(); program.setTailoringQCQs(tailoredQCQs); // "parse" is a better term if (verbose) System.out.println("Compiling " + fileName); Reader file = new BufferedReader(new FileReader(fileName)); if (fileName.endsWith(".sfdl")) { // compile from sfdl file SFECompiler compiler = new SFECompiler(file); try { compiler.compileProgram(program); } catch (ParseException pe) { if (verbose) { pe.printStackTrace(); } System.err.println("Error in line " + pe.getErrorOffset() + ": " + pe.getMessage()); System.exit(1); } } else if (fileName.endsWith(".c")) { // compile from C file CCompiler compiler = new CCompiler(file); // Does its own error checking. compiler.compileProgram(program); } else { String[] extension = fileName.split("\\."); throw new RuntimeException( "I don't know how to compile file with extension " + extension[extension.length - 1]); } file.close(); program.addInputStatements(); program.addOutputStatements(); program.toSLPTCircuit(null); // This only partially reduces the // circuit to SLPT form, specifically the innards of if statements // have their transformation postponed until later in compilation. // TODO: For ease of explanation, always do this later in the compilation cycle. computation = Program.main.getBody(); outputConstants = true; } } if (job.contains("w")) { // write circuit PrintWriter circuit = new PrintWriter(new FileWriter(circuitFile)); if (verbose) System.out.println("Expanding circuit to file " + circuitFile); StatementBuffer sb = new StatementBuffer(statementBufferSize, circuit); Program.resetCounter(0); Optimizer.initOptimizer(); AssignmentStatement.doRedundantVarAnalysisForAllVariables = job.contains("r"); AssignmentStatement.combineExpressions = job.contains("m"); AssignmentStatement.removeFractions = job.contains("f"); computation.toAssignmentStatements(sb); sb.flush(); circuit.close(); } String constraintsFile = outFileName + ".spec"; if (outputConstants) { // Write out any constants, needed for the exogenous prover to agree // with our compiled version of this computation. Do this only when compiling from .sfdl. String consFile = constraintsFile + ".cons"; if (verbose) System.out.println("Writing constant values to " + consFile); compileConstants(consFile, defsFile); } // analysis and output to other forms if (job.contains("a")) { // tailoring analysis. read circuit back in, write out .dot file. /* String graphFile = outFileName + ".dot"; compileMultiplicationGraph(circuitFile, graphFile); if (tailoredQCQs > 0) { // Read the graph file back in and analyze connected components QuerySelect.main(new String[] { graphFile, "" + tailoredQCQs }); } */ // read circuit file back in, write out constraints file ConstraintWriter cw = new ConstraintWriter(circuitFile); if (Optimizer.optimizationTarget == Optimizer.Target.ZAATAR) { String uncleanConstraints = constraintsFile + "_tmp"; cw.toConstraints(uncleanConstraints); ConstraintCleaner.cleanupConstraints(uncleanConstraints, constraintsFile); } else { cw.toConstraints(constraintsFile); } // System.out.println("Compilation took "+(System.nanoTime() - // nanoTimeNow) /1e9+" seconds"); } }
public void parse(Path file) throws IOException { clear(); try (BufferedReader inp = Files.newBufferedReader(file)) { String line; while ((line = inp.readLine()) != null) { if (line.startsWith("Cpu ")) { PerfKey key = new PerfKey(); PerfData data = new PerfData(); // Cpu 0 NSE-AB Init Lock Pgs 19 Mem Pages 4194304 key.cpu = Integer.parseInt(line.substring(4, 6).trim()); data.memPages = Integer.parseInt(line.substring(62).trim()); line = inp.readLine(); // Memory MB 65536 PCBs 12100 Pg Size 16384 Bytes if (line == null || !line.startsWith("Memory MB")) { throw new IOException("Строка должна начинаться с 'Memory MB': " + line); } line = inp.readLine(); // IPUs 4 if (line == null || !line.startsWith("IPUs")) { throw new IOException("Строка должна начинаться с 'IPUs': " + line); } line = inp.readLine(); // Format Version: H07 Data Version: H07 Subsystem Version: 3 if (line == null || !line.startsWith("Format Version:")) { throw new IOException("Строка должна начинаться с 'Format Version:': " + line); } line = inp.readLine(); // Local System \KHAFE1 From 1 Oct 2016, 0:00:01 For 5.1 Minutes if (line == null || !line.startsWith("Local System")) { throw new IOException("Строка должна начинаться с 'Local System:': " + line); } key.system = line.substring(13, 21).trim(); String str = line.substring(28, 49); try { key.date = DATETIME_SDF.parse(str); data.duration = parseDuration(line.substring(56).trim()); } catch (ParseException e) { throw new IOException( "Ошибка декодирования строки (Позиция. " + e.getErrorOffset() + "): " + str + ". Строка:" + line, e); } catch (NumberFormatException e) { throw new IOException("Ошибка декодирования строки : " + str + ". Строка:" + line, e); } line = inp.readLine(); // ---------------------------------------------------------------------------- if (line == null || !line.startsWith("---------")) { throw new IOException("Строка должна начинаться с '---------:': " + line); } line = inp.readLine(); // Cpu-Busy-Time 79.99 % Dispatches 115,637 /s if (line == null || !line.startsWith("Cpu-Busy-Time")) { throw new IOException("Строка должна начинаться с 'Cpu-Busy-Time': " + line); } str = line.substring(25, 33).trim(); try { data.cpuBusyTime = DF.parse(str).floatValue(); } catch (ParseException e) { throw new IOException("Ошибка декодирования Cpu-Busy-Time: " + str, e); } line = inp.readLine(); // Cpu-Qtime 13.89 AQL Intr-Busy-Time 14.41 % if (line == null || !line.startsWith("Cpu-Qtime")) { throw new IOException("Строка должна начинаться с 'Cpu-Qtime': " + line); } line = inp.readLine(); // Starting-Free-Mem 3,267,922 # Ending-Free-Mem 3,267,951 # if (line == null || !line.startsWith("Starting-Free-Mem")) { throw new IOException("Строка должна начинаться с 'Starting-Free-Mem': " + line); } str = line.substring(55, 73).trim(); try { data.endingFreeMem = DF.parse(str).intValue(); } catch (ParseException e) { throw new IOException("Ошибка декодирования Ending-Free-Mem: " + str, e); } line = inp.readLine(); // Swaps 1.10 /s Page-Requests 2.19 /s if (line == null || !line.startsWith("Swaps")) { throw new IOException("Строка должна начинаться с 'Swaps': " + line); } line = inp.readLine(); // Disc-IOs 49.79 /s Cache-Hits 946.87 /s if (line == null || !line.startsWith("Disc-IOs")) { throw new IOException("Строка должна начинаться с 'Disc-IOs': " + line); } this.stat.addPerfData(key, data); } } } }