List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:com.ettrema.zsync.Upload.java
/** * Returns the next String terminated by one of the specified delimiters or the end of the InputStream.<p/> * /*ww w . j a v a 2 s . co m*/ * This method simply reads from an InputStream one byte at a time, up to maxsearch bytes, until it reads a byte equal to one of the delimiters * or reaches the end of the stream. It uses the CHARSET encoding to translate the bytes read into a String, which it returns with delimiter excluded, * or it throws a ParseException if maxSearch bytes are read without reaching a delimiter or the end of the stream.<p/> * * A non-buffering method is used because a buffering reader would likely pull in part of the binary data * from the InputStream. An alternative is to use a BufferedReader with a given buffer size and use * mark and reset to get back binary data pulled into the buffer. * * @param in The InputStream to read from * @param delimiters A list of byte values, each of which indicates the end of a token * @param maxsearch The maximum number of bytes to search for a delimiter * @return The String containing the CHARSET decoded String with delimiter excluded * @throws IOException * @throws ParseException If a delimiter byte is not found within maxsearch reads */ public static String readToken(InputStream in, byte[] delimiters, int maxsearch) throws ParseException, IOException { if (maxsearch <= 0) { throw new RuntimeException("readToken: Invalid maxsearch " + maxsearch); } ByteBuffer bytes = ByteBuffer.allocate(maxsearch); byte nextByte; try { read: while ((nextByte = (byte) in.read()) > -1) { for (byte delimiter : delimiters) { if (nextByte == delimiter) { break read; } } bytes.put(nextByte); } bytes.flip(); return Charset.forName(CHARSET).decode(bytes).toString(); } catch (BufferOverflowException ex) { throw new ParseException("Could not find delimiter within " + maxsearch + " bytes.", 0); } }
From source file:com.stratelia.webactiv.util.DateUtil.java
public static Date stringToDate(String date, String hour, String language) throws ParseException { try {/*from www. ja v a 2 s. c o m*/ SimpleDateFormat format; if (hour == null || "".equals(hour.trim())) { format = getDateInputFormat(language); return format.parse(date); } format = getDateAndHourInputFormat(language); return format.parse(date + " " + hour); } catch (Exception e) { throw new ParseException(e.getMessage(), 0); } }
From source file:com.datastax.loader.CqlDelimParser.java
private List<SchemaBits> schemaBits(String in, Session session) throws ParseException { KeyspaceMetadata km = session.getCluster().getMetadata().getKeyspace(keyspace); if (null == km) { System.err.println("Keyspace " + keyspace + " not found."); System.exit(-1);/*from w ww . j a v a 2 s . co m*/ } TableMetadata tm = km.getTable(tablename); if (null == tm) { System.err.println("Table " + tablename + " not found."); System.exit(-1); } List<String> inList = new ArrayList<String>(); if (null != in) { String[] tlist = in.split(","); for (int i = 0; i < tlist.length; i++) inList.add(tlist[i].trim()); } else { for (ColumnMetadata cm : tm.getColumns()) inList.add("\"" + cm.getName() + "\""); } //keep the list of columns from metadata to use as column backbone for JSON setColumnNames(inList); List<SchemaBits> sbl = new ArrayList<SchemaBits>(); for (int i = 0; i < inList.size(); i++) { String col = inList.get(i); SchemaBits sb = new SchemaBits(); ColumnMetadata cm = tm.getColumn(col); if (null == cm) { System.err.println("Column " + col + " of table " + keyspace + "." + tablename + " not found"); System.exit(-1); } DataType dt = cm.getType(); sb.name = col; sb.datatype = dt.getName(); if (dt.isCollection()) { if (sb.datatype == DataType.Name.LIST) { DataType.Name listType = dt.getTypeArguments().get(0).getName(); Parser listParser = pmap.get(listType); if (null == listParser) { throw new ParseException("List data type not recognized (" + listType + ")", i); } sb.parser = new ListParser(listParser, ',', '[', ']'); } else if (sb.datatype == DataType.Name.SET) { DataType.Name setType = dt.getTypeArguments().get(0).getName(); Parser setParser = pmap.get(setType); if (null == setParser) { throw new ParseException("Set data type not recognized (" + setType + ")", i); } sb.parser = new SetParser(setParser, ',', '{', '}'); } else if (sb.datatype == DataType.Name.MAP) { DataType.Name keyType = dt.getTypeArguments().get(0).getName(); Parser keyParser = pmap.get(keyType); if (null == keyParser) { throw new ParseException("Map key data type not recognized (" + keyType + ")", i); } DataType.Name valueType = dt.getTypeArguments().get(1).getName(); Parser valueParser = pmap.get(valueType); if (null == valueParser) { throw new ParseException("Map value data type not recognized (" + valueType + ")", i); } sb.parser = new MapParser(keyParser, valueParser, ',', '{', '}', ':'); } else { throw new ParseException("Collection data type not recognized (" + sb.datatype + ")", i); } } else { sb.parser = pmap.get(sb.datatype); if (null == sb.parser) { throw new ParseException("Column data type not recognized (" + sb.datatype + ")", i); } } sbl.add(sb); } return sbl; }
From source file:org.kalypso.wspwin.core.WspCfg.java
private IStatus readWspCfg(final File profDir, final Collection<ZustandBean> zustandBeans) { final File wspCfgFile = new File(profDir, WspWinFiles.WSP_CFG); try (LineNumberReader reader = new LineNumberReader(new FileReader(wspCfgFile))) { final String firstLine = reader.readLine(); if (firstLine == null || firstLine.length() == 0) return new Status(IStatus.ERROR, KalypsoWspWinCorePlugin.PLUGIN_ID, Messages.getString("org.kalypso.wspwin.core.WspCfg.1")); //$NON-NLS-1$ // ignore the values, we read the count from the linecount // just parse the type final char type = firstLine.charAt(firstLine.length() - 1); setType(type);/*from w w w . j a va2 s . c o m*/ while (reader.ready()) { final String line = reader.readLine(); if (line == null) break; final String trimmedLine = line.trim(); if (trimmedLine.length() == 0 || trimmedLine.length() < 85) continue; try { final String waterName = trimmedLine.substring(0, 15).trim(); final String name = trimmedLine.substring(15, 30).trim(); // normally it should always be german, but it depends on the wspwin installation final DateFormat dateInstance = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Locale.GERMAN); final String dateString = trimmedLine.substring(30, 41).trim(); final Date date = dateInstance.parse(dateString); final BigDecimal start = new BigDecimal(trimmedLine.substring(41, 56).trim()); final BigDecimal end = new BigDecimal(trimmedLine.substring(56, 71).trim()); final String fileName = trimmedLine.substring(71).trim(); final ZustandBean zustandBean = new ZustandBean(name, waterName, fileName, start, end, date); zustandBeans.add(zustandBean); } catch (final NumberFormatException e) { e.printStackTrace(); throw new ParseException( Messages.getString("org.kalypso.wspwin.core.WspCfg.3", reader.getLineNumber()), //$NON-NLS-1$ reader.getLineNumber()); } } return Status.OK_STATUS; } catch (final ParseException | IOException e) { return new Status(IStatus.ERROR, KalypsoWspWinCorePlugin.PLUGIN_ID, e.getLocalizedMessage(), e); } }
From source file:FormatTest.java
public String valueToString(Object value) throws ParseException { if (!(value instanceof byte[])) throw new ParseException("Not a byte[]", 0); byte[] a = (byte[]) value; if (a.length != 4) throw new ParseException("Length != 4", 0); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 4; i++) { int b = a[i]; if (b < 0) b += 256;// w w w .j a v a 2s .c o m builder.append(String.valueOf(b)); if (i < 3) builder.append('.'); } return builder.toString(); }
From source file:org.deidentifier.arx.DataHandle.java
/** * Returns a long value from the specified cell. * * @param row The cell's row index/*w w w. j av a 2 s.co m*/ * @param col The cell's column index * @return the long * @throws ParseException the parse exception */ public Long getLong(int row, int col) throws ParseException { String value = getValue(row, col); DataType<?> type = getDataType(getAttributeName(col)); if (type instanceof ARXInteger) { return ((ARXInteger) type).parse(value); } else { throw new ParseException("Invalid datatype: " + type.getClass().getSimpleName(), col); } }
From source file:org.jamwiki.utils.XMLUtil.java
/** * Given an <code>InputSource</code> object that points to XML data, parse * the XML and return a parsed <code>Document</code> object. * * @param source The InputSource object that points to XML data. * @param validating Set to <code>true</code> if the parser should * validate against a DTD.//from ww w. j a v a 2 s . co m * @return A parsed Document object. * @throws ParseException Thrown if any error occurs during parsing. */ public static Document parseXML(InputSource source, boolean validating) throws ParseException { // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validating); // Create the builder and parse the file try { return factory.newDocumentBuilder().parse(source); } catch (IOException e) { ParseException pe = new ParseException("IO exception while parsing XML", -1); pe.initCause(e); throw pe; } catch (ParserConfigurationException e) { ParseException pe = new ParseException("XML could not be parsed", -1); pe.initCause(e); throw pe; } catch (SAXException e) { ParseException pe = new ParseException("XML contains invalid XML", -1); pe.initCause(e); throw pe; } }
From source file:org.unitedinternet.cosmo.calendar.query.ComponentFilter.java
private void validateName(Element element) throws ParseException { name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null); if (name == null) { throw new ParseException("CALDAV:comp-filter a calendar component name (e.g., \"VEVENT\") is required", -1);/*w w w.j a v a 2 s . c om*/ } if (!(name.equals(Calendar.VCALENDAR) || CalendarUtils.isSupportedComponent(name) || name.equals(Component.VALARM) || name.equals(Component.VTIMEZONE))) { throw new ParseException(name + " is not a supported iCalendar component", -1); } }
From source file:com.adobe.ags.curly.controller.ActionRunner.java
private void parseCommand(Action action) throws ParseException { this.action = action; String commandStr = tokenizeParameters(action.getCommand()); List<String> parts = splitByUnquotedSpaces(commandStr); URL = detokenizeParameters(parts.remove(parts.size() - 1)); int offset = 0; for (int i = 0; i < parts.size(); i++) { String part = parts.get(i); if (part.startsWith("-")) { if (part.length() == 2 && i < parts.size() - 1) { if (parseCmdParam(part.charAt(1), parts.get(i + 1), offset)) { i++;/* w w w . j av a 2 s .c o m*/ } } else { parseCmdParam(part.charAt(1), part.substring(2), offset); } } else { throw new ParseException(ApplicationState.getMessage(UNKNOWN_PARAMETER) + ": " + part, offset); } offset += part.length() + 1; } }
From source file:org.unitedinternet.cosmo.calendar.ICalDate.java
/** * Parses dates./*from w ww . jav a 2 s. c o m*/ * @param str The string. * @throws ParseException - if something is wrong this exception is thrown. */ private void parseDates(String str) throws ParseException { if (str.indexOf(',') == -1) { date = isDate() ? new Date(str) : new DateTime(str, tz); if (isDate() && tz != null) { throw new ParseException("DATE cannot have timezone", 0); } } dates = isDate() ? new DateList(str, Value.DATE, tz) : new DateList(str, Value.DATE_TIME, tz); }