List of usage examples for java.lang Byte Byte
@Deprecated(since = "9") public Byte(String s) throws NumberFormatException
From source file:ar.com.fdvs.dj.core.layout.Dj2JrCrosstabBuilder.java
/** * The way to create the cells is like this:<br><br> * * the result is a matrix of (cols+1)*(rows+1) cells.<br> * Each cell has 2 properties that describes which row and column they belong (like coordinates).<br><br> * * null/null | col(n)/null | ... | col(1)/null <br> * -------------------------------------------------- <br> * null/row(n) | col(n)/row(n) | ... | col(1)/row(n) <br> * -------------------------------------------------- <br> * null/... | col(n)/... | ... | col(1)/... <br> * -------------------------------------------------- <br> * null/row(1) | col(n)/row(1) | ... | col(1)/row(1) <br> * *<br><br>//from w w w.j a v a 2 s .c o m * you get this matrix with this two vectors<br> * cols: {null, col(n), ..., col(1)}<br> * rows: {null, row(n), ..., row(1)}<br> *<br> * where the col(n) is the outer most column, and row(n) is the outer most row in the crosstab<br><br> * * The cell with null/null is the inner most cell in the crosstab<br> * * @param djcross */ protected void createCells() { DJCrosstabColumn auxCol = new DJCrosstabColumn(); DJCrosstabRow auxRow = new DJCrosstabRow(); try { BeanUtils.copyProperties(auxCol, djcross.getColumns().get(djcross.getColumns().size() - 1)); BeanUtils.copyProperties(auxRow, djcross.getRows().get(djcross.getRows().size() - 1)); } catch (Exception e) { log.error(e.getMessage(), e); //must not happend } auxCol.setProperty(null); auxRow.setProperty(null); List auxColsList = new ArrayList(djcross.getColumns()); auxColsList.add(auxCol); List auxRowsList = new ArrayList(djcross.getRows()); auxRowsList.add(auxRow); DJCrosstabColumn[] auxCols = (DJCrosstabColumn[]) auxColsList.toArray(new DJCrosstabColumn[] {}); DJCrosstabRow[] auxRows = (DJCrosstabRow[]) auxRowsList.toArray(new DJCrosstabRow[] {}); for (int i = auxCols.length - 1; i >= 0; i--) { for (int j = auxRows.length - 1; j >= 0; j--) { DJCrosstabColumn crosstabColumn = auxCols[i]; DJCrosstabRow crosstabRow = auxRows[j]; JRDesignCrosstabCell cell = new JRDesignCrosstabCell(); cell.setWidth(new Integer(crosstabColumn.getWidth())); cell.setHeight(new Integer(crosstabRow.getHeight())); boolean isRowTotal = crosstabRow.getProperty() != null; boolean isColumnTotal = crosstabColumn.getProperty() != null; if (isColumnTotal) cell.setColumnTotalGroup(crosstabColumn.getProperty().getProperty()); if (isRowTotal) cell.setRowTotalGroup(crosstabRow.getProperty().getProperty()); JRDesignCellContents contents = new JRDesignCellContents(); int measureIdx = 0; int measureHeight = crosstabRow.getHeight() / djcross.getMeasures().size(); for (Iterator iterator = djcross.getMeasures().iterator(); iterator.hasNext(); measureIdx++) { DJCrosstabMeasure djmeasure = (DJCrosstabMeasure) iterator.next(); String meausrePrefix = "idx" + measureIdx + "_"; JRDesignTextField element = new JRDesignTextField(); element.setWidth(crosstabColumn.getWidth()); element.setHeight(measureHeight); element.setY(measureIdx * measureHeight); JRDesignExpression measureExp = new JRDesignExpression(); boolean isTotalCell = isRowTotal || isColumnTotal; String measureProperty = meausrePrefix + djmeasure.getProperty().getProperty(); String measureValueClassName = djmeasure.getProperty().getValueClassName(); if (!isTotalCell) { if (djmeasure.getValueFormatter() == null) { measureExp.setValueClassName(measureValueClassName); //FIXME Shouldn't this be of a class "compatible" with measure's operation? measureExp.setText("$V{" + measureProperty + "}"); } else { measureExp.setText(djmeasure.getTextForValueFormatterExpression(measureProperty)); measureExp.setValueClassName(djmeasure.getValueFormatter().getClassName()); } } else { //is a total cell if (djmeasure.getValueFormatter() == null) { if (djmeasure.getPrecalculatedTotalProvider() == null) { measureExp.setValueClassName(measureValueClassName); measureExp.setText("$V{" + measureProperty + "}"); } else { //call the precalculated value. setExpressionForPrecalculatedTotalValue(auxCols, auxRows, measureExp, djmeasure, crosstabColumn, crosstabRow, meausrePrefix); } } else { //have value formatter if (djmeasure.getPrecalculatedTotalProvider() == null) { //has value formatter, no total provider measureExp.setText(djmeasure.getTextForValueFormatterExpression(measureProperty)); measureExp.setValueClassName(djmeasure.getValueFormatter().getClassName()); } else { //NO value formatter, call the precalculated value only setExpressionForPrecalculatedTotalValue(auxCols, auxRows, measureExp, djmeasure, crosstabColumn, crosstabRow, meausrePrefix); } } } element.setExpression(measureExp); //measure if (!isRowTotal && !isColumnTotal && djmeasure.getStyle() != null) { //this is the inner most cell layoutManager.applyStyleToElement(djmeasure.getStyle(), element); } //row total only if (isRowTotal && !isColumnTotal) { Style style = getRowTotalStyle(crosstabRow); if (style == null) style = djmeasure.getStyle(); if (style != null) layoutManager.applyStyleToElement(style, element); } //column total only if (isColumnTotal && !isRowTotal) { Style style = getColumnTotalStyle(crosstabColumn); if (style == null) style = djmeasure.getStyle(); if (style != null) layoutManager.applyStyleToElement(style, element); } //row and column total if (isRowTotal && isColumnTotal) { Style style = getRowTotalStyle(crosstabRow); if (style == null) style = getColumnTotalStyle(crosstabColumn); if (style == null) style = djmeasure.getStyle(); if (style != null) layoutManager.applyStyleToElement(style, element); } JRDesignStyle jrstyle = (JRDesignStyle) element.getStyle(); //FIXME this is a hack if (jrstyle == null) { if (log.isDebugEnabled()) { log.warn("jrstyle is null in crosstab cell, this should have not happened."); } layoutManager.applyStyleToElement(null, element); jrstyle = (JRDesignStyle) element.getStyle(); jrstyle.setBlankWhenNull(true); } JRDesignStyle alternateStyle = Utils.cloneStyle(jrstyle); alternateStyle.setName(alternateStyle.getFontName() + "_for_column_" + djmeasure.getProperty()); alternateStyle.getConditionalStyleList().clear(); element.setStyle(alternateStyle); try { design.addStyle(alternateStyle); } catch (JRException e) { /**e.printStackTrace(); //Already there, nothing to do **/ } setUpConditionStyles(alternateStyle, djmeasure, measureExp.getText()); if (djmeasure.getLink() != null) { String name = "cell_" + i + "_" + j + "_ope" + djmeasure.getOperation().getValue(); HyperLinkUtil.applyHyperLinkToElement((DynamicJasperDesign) this.design, djmeasure.getLink(), element, name); } contents.addElement(element); } contents.setMode(new Byte(Transparency.OPAQUE.getValue())); applyBackgroundColor(contents, crosstabRow, crosstabColumn, i, j); applyCellBorder(contents); cell.setContents(contents); try { jrcross.addCell(cell); } catch (JRException e) { log.error(e.getMessage(), e); } } } }
From source file:org.plasma.sdo.helper.DataConverter.java
public Object fromDouble(Type targetType, double value) { DataType targetDataType = DataType.valueOf(targetType.getName()); switch (targetDataType) { case Double: return Double.valueOf(value); case Byte: return new Byte(Double.valueOf(value).byteValue()); case Float: return new Float(Double.valueOf(value).floatValue()); case Int://from w w w . j a v a 2 s.com return new Integer(Double.valueOf(value).intValue()); case Long: return new Long(Double.valueOf(value).longValue()); case Short: return new Short(Double.valueOf(value).shortValue()); case Integer: return BigInteger.valueOf(Double.valueOf(value).longValue()); case Decimal: return BigDecimal.valueOf(value); case String: // as per spec: Decimal | 'NaN' | '-NaN' | 'Infinity' | '-Infinity' return Double.toString(value); default: throw new InvalidDataConversionException(targetDataType, DataType.Double, value); } }
From source file:com.draagon.meta.manager.ObjectManager.java
protected static boolean compareValue(Object val, Object val2, int condition) { // If it's a collection, then iterate the whole array if (val2 instanceof Collection) { // Has to be EQUAL or NOT EQUAL if (condition != Expression.EQUAL && condition != Expression.NOT_EQUAL) { throw new IllegalArgumentException( "Can only compare with EQUAL or NOT EQUAL against a collection!"); }/*from w w w .j a v a2s . c o m*/ // Iterate each value in the collection for (Object v : ((Collection<?>) val2)) { // Get the resulting condition boolean ret = compareValue(val, v, condition); // return true if there are any matches if (condition == Expression.EQUAL && ret) return true; // if looking for not equal, return false when finding the first one else if (condition == Expression.NOT_EQUAL && !ret) return false; } // Return true or false based on the condition if (condition == Expression.EQUAL) return false; else if (condition == Expression.NOT_EQUAL) return true; else throw new IllegalStateException("This has to be EQUAL or NOT EQUAL"); } int result = 0; if (val == null || val2 == null) { if (val == null && val2 == null) result = 0; else if (val == null) result = -1; else result = 1; } else if (val instanceof Boolean) { if (((Boolean) val).equals(val2)) result = 0; else result = 1; } else if (val instanceof Byte) { Byte v = (val2 instanceof Byte) ? (Byte) val2 : new Byte(val2.toString()); result = ((Byte) val).compareTo(v); } else if (val instanceof Short) { Short v = (val2 instanceof Short) ? (Short) val2 : new Short(val2.toString()); result = ((Short) val).compareTo(v); } else if (val instanceof Integer) { Integer v = (val2 instanceof Integer) ? (Integer) val2 : new Integer(val2.toString()); result = ((Integer) val).compareTo(v); } else if (val instanceof Long) { Long v = (val2 instanceof Long) ? (Long) val2 : new Long(val2.toString()); result = ((Long) val).compareTo(v); } else if (val instanceof Float) { Float v = (val2 instanceof Float) ? (Float) val2 : new Float(val2.toString()); result = ((Float) val).compareTo(v); } else if (val instanceof Double) { Double v = (val2 instanceof Double) ? (Double) val2 : new Double(val2.toString()); result = ((Double) val).compareTo(v); } else if (val instanceof Date) { Date v = (val2 instanceof Date) ? (Date) val2 : new Date(Long.parseLong(val2.toString())); result = ((Date) val).compareTo(v); } else { result = val.toString().toLowerCase().compareTo(val2.toString().toLowerCase()); } switch (condition) { case Expression.EQUAL: if (result == 0) return true; else return false; case Expression.GREATER: if (result > 0) return true; else return false; case Expression.LESSER: if (result < 0) return true; else return false; case Expression.EQUAL_GREATER: if (result >= 0) return true; else return false; case Expression.EQUAL_LESSER: if (result <= 0) return true; else return false; case Expression.NOT_EQUAL: if (result != 0) return true; else return false; default: throw new IllegalArgumentException( "Invalid expression condition [" + Expression.condStr(condition) + "]"); } }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportJobsQuartzScheduler.java
protected Date getStartDate(ReportJobTrigger jobTrigger) { Date startDate;//from w ww . j a va2 s . c o m switch (jobTrigger.getStartType()) { case ReportJobTrigger.START_TYPE_NOW: Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); startDate = calendar.getTime(); break; case ReportJobTrigger.START_TYPE_SCHEDULE: startDate = translateFromTriggerTimeZone(jobTrigger, jobTrigger.getStartDate()); break; default: throw new JSException("jsexception.job.unknown.start.type", new Object[] { new Byte(jobTrigger.getStartType()) }); } return startDate; }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Reads a <CODE>String</CODE> from the stream message. * * @return a Unicode string from the stream message * @throws JMSException//from w w w . j a v a2 s . com * if the JMS provider fails to read the message due to some * internal error. * @throws MessageEOFException * if unexpected end of message stream has been reached. * @throws MessageFormatException * if this type conversion is invalid. * @throws MessageNotReadableException * if the message is in write-only mode. */ public String readString() throws JMSException { initializeReading(); try { this.dataIn.mark(65); int type = this.dataIn.read(); if (type == -1) { throw new MessageEOFException("reached end of data"); } if (type == MarshallingSupport.NULL) { return null; } if (type == MarshallingSupport.BIG_STRING_TYPE) { return MarshallingSupport.readUTF8(dataIn); } if (type == MarshallingSupport.STRING_TYPE) { return this.dataIn.readUTF(); } if (type == MarshallingSupport.LONG_TYPE) { return new Long(this.dataIn.readLong()).toString(); } if (type == MarshallingSupport.INTEGER_TYPE) { return new Integer(this.dataIn.readInt()).toString(); } if (type == MarshallingSupport.SHORT_TYPE) { return new Short(this.dataIn.readShort()).toString(); } if (type == MarshallingSupport.BYTE_TYPE) { return new Byte(this.dataIn.readByte()).toString(); } if (type == MarshallingSupport.FLOAT_TYPE) { return new Float(this.dataIn.readFloat()).toString(); } if (type == MarshallingSupport.DOUBLE_TYPE) { return new Double(this.dataIn.readDouble()).toString(); } if (type == MarshallingSupport.BOOLEAN_TYPE) { return (this.dataIn.readBoolean() ? Boolean.TRUE : Boolean.FALSE).toString(); } if (type == MarshallingSupport.CHAR_TYPE) { return new Character(this.dataIn.readChar()).toString(); } else { this.dataIn.reset(); throw new MessageFormatException(" not a String type"); } } catch (NumberFormatException mfe) { try { this.dataIn.reset(); } catch (IOException ioe) { JMSException jmsEx = new MessageFormatException(ioe.getMessage()); jmsEx.setLinkedException(ioe); throw jmsEx; } throw mfe; } catch (EOFException e) { String exMessage = "Reached premature EOF: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } catch (IOException e) { String exMessage = "Could not read boolean: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:com.p2p.peercds.common.Torrent.java
/** * Helper method to create a {@link Torrent} object for a set of files. * * <p>//from w w w.java 2 s .c o m * Hash the given files to create the multi-file {@link Torrent} object * representing the Torrent meta-info about them, needed for announcing * and/or sharing these files. Since we created the torrent, we're * considering we'll be a full initial seeder for it. * </p> * * @param parent The parent directory or location of the torrent files, * also used as the torrent's name. * @param files The files to add into this torrent. * @param announce The announce URI that will be used for this torrent. * @param announceList The announce URIs organized as tiers that will * be used for this torrent * @param createdBy The creator's name, or any string identifying the * torrent's creator. */ private static Torrent create(File parent, List<File> files, URI announce, List<List<URI>> announceList, String createdBy) throws InterruptedException, IOException { MessageDigest md = DigestUtils.getSha1Digest(); if (files == null || files.isEmpty()) { logger.info("Creating single-file torrent for {}...", parent.getName()); } else { logger.info("Creating {}-file torrent {}...", files.size(), parent.getName()); } Map<String, BEValue> torrent = new HashMap<String, BEValue>(); if (announce != null) { torrent.put("announce", new BEValue(announce.toString())); } if (announceList != null) { List<BEValue> tiers = new LinkedList<BEValue>(); for (List<URI> trackers : announceList) { List<BEValue> tierInfo = new LinkedList<BEValue>(); for (URI trackerURI : trackers) { tierInfo.add(new BEValue(trackerURI.toString())); } tiers.add(new BEValue(tierInfo)); } torrent.put("announce-list", new BEValue(tiers)); } torrent.put("creation date", new BEValue(new Date().getTime() / 1000)); torrent.put("created by", new BEValue(createdBy)); Map<String, BEValue> info = new HashMap<String, BEValue>(); info.put("name", new BEValue(parent.getName())); info.put("piece length", new BEValue(PIECE_LENGTH)); long size = 0; int numFiles = 0; if (files == null || files.isEmpty()) { info.put("length", new BEValue(parent.length())); size = parent.length(); numFiles++; info.put("pieces", new BEValue(Torrent.hashFile(parent), BYTE_ENCODING)); } else { List<BEValue> fileInfo = new LinkedList<BEValue>(); List<File> updatedFilesList = new ArrayList<File>(); updateFileInfo(files, parent, parent, fileInfo, updatedFilesList); logger.info("Number of files in this multi-file torrent: " + updatedFilesList.size()); for (File file : updatedFilesList) size = size + file.length(); logger.info("Number of bytes in this multi-file torrent: " + size); numFiles = updatedFilesList.size(); info.put("files", new BEValue(fileInfo)); BEValue piecesValue = new BEValue(Torrent.hashFiles(updatedFilesList), BYTE_ENCODING); info.put("pieces", piecesValue); } TreeMap<String, BEValue> sortInfoMap = new TreeMap<String, BEValue>(); sortInfoMap.putAll(info); info = new HashMap<String, BEValue>(); info.putAll(sortInfoMap); sortInfoMap = null; torrent.put("info", new BEValue(info)); md.update(torrent.get("info").getMap().get("pieces").getBytes()); byte[] digest = md.digest(); byte[] transformedDigest = new byte[digest.length]; int i = 0; for (byte bt : digest) { short s = (short) (bt & 0xFF); if (s >= 127) { s = (short) (s - 127); if (s < 32) s = (short) (s + 32); } else if (s < 32) s = (short) (s + 32); transformedDigest[i++] = (byte) s; } for (byte b : transformedDigest) logger.debug(new Byte(b).toString()); logger.info("digest str " + new String(digest)); logger.info("transformed digest str " + new String(transformedDigest)); logger.info("Replacing special characters in the cloud key with regular characters"); String cloudKeyForFile = new String(transformedDigest, "UTF-8"); for (String nsChar : SPECIAL_TO_NSP_MAP.keySet()) { if (cloudKeyForFile.contains(nsChar)) cloudKeyForFile = cloudKeyForFile.replaceAll(java.util.regex.Pattern.quote(nsChar), SPECIAL_TO_NSP_MAP.get(nsChar)); } logger.info("Sanitized cloud Key: " + cloudKeyForFile); CloudUploadProgressListener listener = new CloudUploadProgressListener(size, numFiles); boolean success = false; try { success = CloudHelper.uploadTorrent(BUCKET_NAME, cloudKeyForFile.trim(), parent, listener); } catch (S3FetchException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!success) logger.info("File won't be uploaded to cloud as file is present in swarm and uploaded to cloud"); else logger.info("New file has been introduced in the swarm and has been uploaded to the cloud"); torrent.put(CLOUD_KEY, new BEValue(cloudKeyForFile)); TreeMap<String, BEValue> sortTorrentMap = new TreeMap<String, BEValue>(); sortTorrentMap.putAll(torrent); torrent = new HashMap<String, BEValue>(); torrent.putAll(sortTorrentMap); sortTorrentMap = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); BEncoder.bencode(new BEValue(torrent), baos); return new Torrent(baos.toByteArray(), true); }
From source file:TypeConversionHelper.java
/** * Convert the value to a instance of the given type. The value converted only * if the type can't be assigned from the current type of the value instance. * @param value the value to be converted * @param type the type of the expected object returned from the coversion * @return the converted object, or null if the object can't be converted */// w ww . ja va 2 s . c o m public static Object convertTo(Object value, Class type) { //check if the id can be assigned for the field type, otherwise convert the id to the appropriate type if (!type.isAssignableFrom(value.getClass())) { if (type == short.class || type == Short.class) { return new Short(value.toString()); } else if (type == char.class || type == Character.class) { return new Character(value.toString().charAt(0)); } else if (type == int.class || type == Integer.class) { return new Integer(value.toString()); } else if (type == long.class || type == Long.class) { return new Long(value.toString()); } else if (type == boolean.class || type == Boolean.class) { return new Boolean(value.toString()); } else if (type == byte.class || type == Byte.class) { return new Byte(value.toString()); } else if (type == float.class || type == Float.class) { return new Float(value.toString()); } else if (type == double.class || type == Double.class) { return new Double(value.toString()); } else if (type == BigDecimal.class) { return new BigDecimal(value.toString()); } else if (type == BigInteger.class) { return new BigInteger(value.toString()); } else if (type == String.class) { return value.toString(); } else { return null; } } return value; }
From source file:org.opoo.oqs.core.AbstractQuery.java
public Query setByte(String name, byte val) { setParameter(name, new Byte(val), Type.BYTE); return this; }
From source file:com.isencia.passerelle.message.TokenHelper.java
/** * Tries to get a Byte from the token, by: * <ul>// ww w . j a v a2s .c o m * <li>checking if the token is not an ObjectToken, containing a Byte * <li>checking if the token is not an ObjectToken, and converting the object.toString() into a Byte * <li>checking if the token is not a StringToken, and converting the string into a Byte * <li>checking if the token is not a ScalarToken, and reading its byte value * </ul> * * @param token * @return */ public static Byte getByteFromToken(Token token) throws PasserelleException { if (logger.isTraceEnabled()) { logger.trace(token.toString()); // TODO Check if correct converted } Byte res = null; if (token != null) { try { if (token instanceof ObjectToken) { Object obj = ((ObjectToken) token).getValue(); if (obj instanceof Byte) { res = (Byte) obj; } else if (obj != null) { try { res = Byte.valueOf(obj.toString()); } catch (NumberFormatException e) { throw new PasserelleException(ErrorCode.MSG_CONTENT_TYPE_ERROR, "Invalid Byte format in " + token, e); } } } else { if (token instanceof StringToken) { String tokenMessage = ((StringToken) token).stringValue(); if (tokenMessage != null) { try { res = Byte.valueOf(tokenMessage); } catch (NumberFormatException e) { throw new PasserelleException(ErrorCode.MSG_CONTENT_TYPE_ERROR, "Invalid Byte format in " + token, e); } } } else if (token instanceof ScalarToken) { res = new Byte(((ScalarToken) token).byteValue()); } else { throw new PasserelleException(ErrorCode.MSG_CONTENT_TYPE_ERROR, "Invalid token for obtaining Byte value in " + token, null); } } } catch (Exception e) { throw new PasserelleException(ErrorCode.MSG_CONTENT_TYPE_ERROR, "Error building Byte from token in " + token, e); } } if (logger.isTraceEnabled()) { logger.trace("exit :" + res); } return res; }
From source file:org.shampoo.goldenembed.parser.GoldenEmbedParserMain.java
private int readBuffer(byte[] readBytes, String filePath) { int bufPos = 0; GPS gps = new GPS(); byte[] bufToSend; byte[] timeStamp; long secs = 0; if ((pos + bufPos + 64) >= readBytes.length - 1) { System.out.println("\n\nTotal Failed Checksums: " + totalChecksumError + " Out of Total ANT Messages: " + totalTrans);/*from w w w .j ava 2 s.c om*/ System.out.println("% ANT Failure: " + (totalChecksumError / totalTrans) * 100.0); System.out.println("Total Failed GPS: " + totalGPSError + " Out of Total ANT Messages: " + totalTrans); System.out.println("% GPS Failure: " + (totalGPSError / totalTrans) * 100.0); System.out.println("Total Failed Messages: " + (totalChecksumError + totalGPSError) + " Out of Total ANT Messages: " + totalTrans); System.out.println("% Failure: " + ((totalChecksumError + totalGPSError) / totalTrans) * 100.0); System.out.println("Total CAD or Watt Spikes: " + totalSpikes); writeOutGCRecords(); System.exit(0); } Byte aByte = new Byte(readBytes[pos + bufPos + 1]); int size = aByte.intValue(); if (size < 0) { pos++; // We failed a checksum skip.. while (readBytes[pos] != MESG_TX_SYNC) { pos++; } totalChecksumError++; return pos; } bufToSend = new byte[size + 4]; for (; bufPos < bufToSend.length; bufPos++) bufToSend[bufPos] = readBytes[bufPos + pos]; if (ANTrxHandler(bufToSend, gc) == true) { pos++; // We failed a checksum skip.. while (readBytes[pos] != MESG_TX_SYNC) pos++; return pos; } pos = (pos + size + 4); try { if (isGPS) { // Now Parse GPS gps = new GPS().GPSHandler(readBytes, pos); pos += 22; // All GPS data // Get the intial elevation from Google use Lat and Lon if (altiPressure == null && serializedElevationPath == null) { altiPressure = new AltitudePressure(GoogleElevation .getElevation(Float.valueOf(gps.getLatitude()), Float.valueOf(gps.getLongitude()))); } int pressureCounter = 0; byte[] pressureByte = new byte[16]; while (readBytes[pos] != 0x07) { if (pressureCounter == 15) throw new NumberFormatException(); pressureByte[pressureCounter++] = readBytes[pos++]; } pos++; // skip the delimeter String strPressure = convertBytesToString(pressureByte); float pressure = Float.parseFloat(strPressure); strPressure = convertBytesToString(pressureByte); pressure = Float.parseFloat(strPressure); if (serializedElevationPath == null) gc.setElevation(altiPressure.altiCalc(pressure / 100.0f)); timeStamp = new byte[6]; for (int i = 0; i < 6; i++) timeStamp[i] = readBytes[pos++]; secs = parseTimeStamp(timeStamp, gc); } else { timeStamp = new byte[3]; for (int i = 0; i < 3; i++) timeStamp[i] = readBytes[pos++]; secs = parseTimeStamp(timeStamp, gc); } if (rideDate == null && isGPS == true) createRideDate(gps, timeStamp); else if (rideDate == null) createRideDate(); gc.setLatitude(gps.getLatitude()); gc.setLongitude(gps.getLongitude()); gc.setSpeed(gps.getSpeed() * KNOTS_TO_KILOMETERS); gc.setDistance(gc.getDistance() + (gc.getSpeed() * (gc.getSecs() - gc.getPrevSpeedSecs()) / 3600.0)); gc.setPrevSpeedSecs(gc.getSecs()); if (secs > 86400) // Only fools ride for more then 24hrs a time.. throw new NumberFormatException(); gc.setSecs(secs); gc.setDate(gps.getDate()); // If we haven't created the file, create it if (outFile == null && outGCFilePath != null) { if (isGPS) initOutFile(gps, outGCFilePath, timeStamp); else createGCOutFile(); } if (gc.getPrevsecs() != gc.getSecs()) { gc.setWatts((int) Round(power.getWatts() / power.getTotalWattCounter(), 0)); gc.setCad((int) Round(power.getRpm() / power.getTotalCadCounter(), 0)); GoldenCheetah _gc = gc.clone(gc); gcArray.add(_gc); gc.setPrevsecs(gc.getSecs()); gc.newWatts = false; } } catch (NumberFormatException e) { while (readBytes[pos] != MESG_TX_SYNC) pos++; totalGPSError++; return pos; } catch (StringIndexOutOfBoundsException ex) { while (readBytes[pos] != MESG_TX_SYNC) pos++; totalGPSError++; } return pos; }