List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:org.lemurproject.galago.core.parse.WARCRecord.java
private static byte[] readNextRecord(DataInputStream in, StringBuffer headerBuffer) throws IOException { if (in == null) { return null; }/*from ww w. jav a2 s .c o m*/ if (headerBuffer == null) { return null; } String line = null; // boolean foundMark = false; byte[] retContent = null; boolean foundMark = findNextWARCRecord(in); // // cannot be using a buffered reader here!!!! // // just read the header // // first - find our WARC header // while ((!foundMark) && ((line = readLineFromInputStream(in)) != null)) { // if (line.startsWith(WARC_VERSION)) { // WARC_VERSION_LINE = line; // foundMark = true; // } // } // no WARC mark? if (!foundMark) { return null; } // LOG.info("Found WARC_VERSION"); int contentLength = -1; // read until we see contentLength then an empty line // (to handle malformed ClueWeb09 headers that have blank lines) // get the content length and set our retContent for (line = readLineFromInputStream(in).trim(); line.length() > 0 || contentLength < 0; line = readLineFromInputStream(in).trim()) { if (line.length() > 0) { headerBuffer.append(line); headerBuffer.append(LINE_ENDING); // find the content length designated by Content-Length: <length> String[] parts = line.split(":", 2); if (parts.length == 2 && parts[0].equals("Content-Length")) { try { contentLength = Integer.parseInt(parts[1].trim()); // LOG.info("WARC record content length: " + contentLength); // if this document is too long if (contentLength > MAX_CONTENT_LENGTH) { in.skip(contentLength); if (!findNextWARCRecord(in)) { return null; } headerBuffer.delete(0, headerBuffer.length()); } } catch (NumberFormatException nfEx) { contentLength = -1; } } } } // now read the bytes of the content retContent = new byte[contentLength]; int totalWant = contentLength; int totalRead = 0; // // LOOP TO REMOVE LEADING CR * LF // To prevent last few characters from being cut off of the content // when reading // while ((totalRead == 0) && (totalRead < contentLength)) { byte CR = in.readByte(); byte LF = in.readByte(); if ((CR != 13) && (LF != 10)) { retContent[0] = CR; retContent[1] = LF; totalRead = 2; totalWant = contentLength - totalRead; } } // // // while (totalRead < contentLength) { try { int numRead = in.read(retContent, totalRead, totalWant); if (numRead < 0) { return null; } else { totalRead += numRead; totalWant = contentLength - totalRead; } // end if (numRead < 0) / else } catch (EOFException eofEx) { // resize to what we have if (totalRead > 0) { byte[] newReturn = new byte[totalRead]; System.arraycopy(retContent, 0, newReturn, 0, totalRead); return newReturn; } else { return null; } } // end try/catch (EOFException) } // end while (totalRead < contentLength) return retContent; }
From source file:org.etudes.tool.melete.SecModObj.java
public String InactivateAction() { FacesContext ctx = FacesContext.getCurrentInstance(); List selModBeans = null;/*w ww . jav a2 s . co m*/ ModuleDateBean mdbean = null; if (sectionSelected) { ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages"); String msg = bundle.getString("select_module"); addMessage(ctx, "Select Module", msg, FacesMessage.SEVERITY_ERROR); sectionSelected = false; moduleSelected = false; count = 0; selectedSecModIndices = null; return "list_auth_modules"; } // module selected if (moduleSelected && selectedModIndices != null) { if (selModBeans == null) { selModBeans = new ArrayList(); } for (ListIterator i = selectedModIndices.listIterator(); i.hasNext();) { mdbean = (ModuleDateBean) moduleDateBeans.get(((Integer) i.next()).intValue()); selModBeans.add(mdbean); } ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages"); try { int origSeqNo = mdbean.getCmod().getSeqNo(); getModuleService().archiveModules(selModBeans, moduleDateBeans, courseId); StringBuffer modTitles = new StringBuffer(); mdbean = null; for (ListIterator i = selModBeans.listIterator(); i.hasNext();) { mdbean = (ModuleDateBean) i.next(); modTitles.append(mdbean.getModule().getTitle()); modTitles.append(", "); } modTitles.delete(modTitles.toString().length() - 2, modTitles.toString().length()); String msg1 = bundle.getString("inactivate_message1"); String msg2 = bundle.getString("inactivate_message2"); addMessage(ctx, "Inactivate Message", msg1 + modTitles.toString() + msg2, FacesMessage.SEVERITY_INFO); } catch (Exception ex) { logger.debug(ex.toString()); String errmsg = bundle.getString("archive_fail"); addMessage(ctx, "Error Message", errmsg, FacesMessage.SEVERITY_ERROR); return "list_auth_modules"; } count = 0; // Mallika - 3/24/05 added this to prevent selected value from being stored moduleSelected = false; sectionSelected = false; return "list_auth_modules"; } if ((moduleSelected == false) && (sectionSelected == false)) { ResourceLoader bundle = new ResourceLoader("org.etudes.tool.melete.bundle.Messages"); String msg = bundle.getString("select_one_module"); addMessage(ctx, "Select One", msg, FacesMessage.SEVERITY_ERROR); } count = 0; moduleSelected = false; sectionSelected = false; return "list_auth_modules"; }
From source file:com.glaf.core.db.TableDataManager.java
public Collection<TableModel> saveAll(String systemName, TableDefinition tableDefinition, String seqNo, Collection<TableModel> rows) { com.glaf.core.config.Environment.setCurrentSystemName(systemName); logger.debug("tableDefinition=" + tableDefinition); logger.debug("idColumn=" + tableDefinition.getIdColumn().toString()); if (tableDefinition.getTableName() != null) { tableDefinition.setTableName(tableDefinition.getTableName().toUpperCase()); }/*from ww w . j a va 2s. co m*/ if (tableDefinition.isInsertOnly()) { return this.insertAll(systemName, tableDefinition, seqNo, rows); } Collection<String> aggregationKeys = new HashSet<String>(); Map<String, Object> colMap = new java.util.HashMap<String, Object>(); Map<String, Object> keyMap = new java.util.HashMap<String, Object>(); Map<String, String> exprMap = new java.util.HashMap<String, String>(); List<ColumnDefinition> exprColumns = new java.util.ArrayList<ColumnDefinition>(); ColumnModel idColumn = new ColumnModel(); ColumnDefinition idCol = tableDefinition.getIdColumn(); if (idCol != null && idCol.getColumnName() != null) { idColumn.setColumnName(idCol.getColumnName()); idColumn.setJavaType(idCol.getJavaType()); idColumn.setValueExpression(idCol.getValueExpression()); } Iterator<ColumnDefinition> iter = tableDefinition.getColumns().iterator(); while (iter.hasNext()) { ColumnDefinition cell = iter.next(); if (StringUtils.isNotEmpty(cell.getValueExpression())) { exprMap.put(cell.getColumnName(), cell.getValueExpression()); exprColumns.add(cell); } } logger.debug(exprMap); String keyCloumns = tableDefinition.getAggregationKeys(); if (StringUtils.isNotEmpty(keyCloumns)) { List<String> cols = StringTools.split(keyCloumns); if (cols != null && !cols.isEmpty()) { StringBuffer buffer = new StringBuffer(1000); Iterator<TableModel> iterator = rows.iterator(); while (iterator.hasNext()) { TableModel tableData = iterator.next(); /** * ?? */ colMap.clear(); buffer.delete(0, buffer.length()); for (ColumnModel cell : tableData.getColumns()) { colMap.put(cell.getColumnName(), cell.getValue()); } Iterator<String> it = cols.iterator(); while (it.hasNext()) { Object val = colMap.get(it.next()); if (val != null) { buffer.append(val.toString()); } else { buffer.append(""); } if (it.hasNext()) { buffer.append("_"); } } String aggregationKey = buffer.toString(); aggregationKeys.add(aggregationKey); tableData.setAggregationKey(aggregationKey);// ?? } if (aggregationKeys.size() > 0 && (aggregationKeys.size() % 200 == 0)) { TableModel model = new TableModel(); model.setTableName(tableDefinition.getTableName()); model.setIdColumn(idColumn); model.setAggregationKeys(aggregationKeys); List<Map<String, Object>> list = getTableDataService().getTableKeyMap(model); if (list != null && !list.isEmpty()) { for (Map<String, Object> dataMap : list) { Object id = ParamUtils.getObject(dataMap, "id"); if (id == null) { id = ParamUtils.getObject(dataMap, "ID"); } String aggregationKey = ParamUtils.getString(dataMap, "aggregationKey"); keyMap.put(aggregationKey, id); } } } } if (aggregationKeys.size() > 0) { TableModel model = new TableModel(); model.setTableName(tableDefinition.getTableName()); model.setIdColumn(idColumn); model.setAggregationKeys(aggregationKeys); List<Map<String, Object>> list = getTableDataService().getTableKeyMap(model); if (list != null && !list.isEmpty()) { for (Map<String, Object> dataMap : list) { Object id = ParamUtils.getObject(dataMap, "id"); if (id == null) { id = ParamUtils.getObject(dataMap, "ID"); } String aggregationKey = ParamUtils.getString(dataMap, "aggregationKey"); keyMap.put(aggregationKey, id); } } } List<TableModel> inertRows = new java.util.ArrayList<TableModel>(); List<TableModel> updateRows = new java.util.ArrayList<TableModel>(); logger.debug(" rows size = " + rows.size()); Iterator<TableModel> iterator = rows.iterator(); while (iterator.hasNext()) { TableModel tableData = iterator.next(); ColumnModel myPK = tableData.getIdColumn(); ColumnModel pkColumn = new ColumnModel(); pkColumn.setColumnName(idColumn.getColumnName()); pkColumn.setJavaType(idColumn.getJavaType()); for (ColumnModel column : tableData.getColumns()) { colMap.put(column.getColumnName(), column.getValue()); } if (keyMap.containsKey(tableData.getAggregationKey())) { Object id = keyMap.get(tableData.getAggregationKey()); pkColumn.setValue(id); tableData.setIdColumn(pkColumn); tableData.removeColumn(pkColumn); updateRows.add(tableData); } else { ColumnModel col = new ColumnModel(); col.setColumnName("AGGREGATIONKEY"); col.setJavaType("String"); col.setValue(tableData.getAggregationKey()); tableData.removeColumn(col); tableData.addColumn(col); for (ColumnDefinition c : exprColumns) { ColumnModel x = new ColumnModel(); x.setColumnName(c.getColumnName()); x.setJavaType(c.getJavaType()); x.setValueExpression(c.getValueExpression()); tableData.addColumn(x); } for (ColumnModel cell : tableData.getColumns()) { String expr = exprMap.get(cell.getColumnName()); if (StringUtils.isNotEmpty(expr)) { if (ExpressionConstants.NOW_EXPRESSION.equals(expr) || ExpressionConstants.CURRENT_YYYYMMDD_EXPRESSION.equals(expr)) { if (cell.getDateValue() == null) { cell.setDateValue(new Date()); cell.setValue(cell.getDateValue()); } } if (ExpressionConstants.ID_EXPRESSION.equals(expr)) { if (cell.getValue() == null) { if (StringUtils.equals(cell.getJavaType(), "Integer")) { cell.setValue(getEntityService().nextId().intValue()); } else if (StringUtils.equals(cell.getJavaType(), "Long")) { cell.setValue(getEntityService().nextId()); } else { cell.setValue(getEntityService().getNextId()); } } } if (ExpressionConstants.SEQNO_EXPRESSION.equals(expr)) { cell.setValue(seqNo); } if (ExpressionConstants.UUID_EXPRESSION.equals(expr)) { cell.setValue(UUID32.getUUID()); } } } if (myPK != null && myPK.getValue() != null) { pkColumn.setValue(myPK.getValue()); } else { if (StringUtils.equals(pkColumn.getJavaType(), "Integer")) { pkColumn.setValue(getEntityService().nextId().intValue()); } else if (StringUtils.equals(pkColumn.getJavaType(), "Long")) { pkColumn.setValue(getEntityService().nextId()); } else { pkColumn.setValue(getEntityService().getNextId()); } } tableData.removeColumn(pkColumn); tableData.addColumn(pkColumn); tableData.setIdColumn(pkColumn); inertRows.add(tableData); } } SqlSession sqlSession = null; Connection conn = null; try { conn = DBConnectionFactory.getConnection(systemName); conn.setAutoCommit(false); sqlSession = getSqlSessionFactory().openSession(ExecutorType.BATCH, conn); if (!inertRows.isEmpty()) { logger.debug("inert rows size:" + inertRows.size()); for (TableModel tableData : inertRows) { tableData.setTableName(tableDefinition.getTableName()); logger.debug(tableData.toString()); sqlSession.insert("insertTableData", tableData); } } if (!updateRows.isEmpty()) { logger.debug("update rows size:" + updateRows.size()); for (TableModel tableData : updateRows) { tableData.setTableName(tableDefinition.getTableName()); sqlSession.insert("updateTableDataByPrimaryKey", tableData); } } sqlSession.commit(); conn.commit(); } catch (Exception ex) { JdbcUtils.rollback(conn); logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(sqlSession); JdbcUtils.close(conn); } return rows; } else { throw new RuntimeException("aggregationKeys is required."); } }
From source file:edu.education.ucsb.muster.MusterServlet.java
private String getOutputAsJson(String database, String query, long limit) throws SQLException { // The output string StringBuffer out = new StringBuffer(); // Cache StringBuffer length as needed int len;/*from w ww .j ava2s . co m*/ // Database operations DatabaseDefinition db = conf.getDatabase(database); // //register the driver registerDriver(db.driver, db.url); // // Connect to the database Connection connection = DriverManager.getConnection(db.url, db.username, db.password); // // Perform the query PreparedStatement statement = connection.prepareStatement(query); statement.execute(); ResultSet results = statement.getResultSet(); // Get and write the column names ResultSetMetaData meta = results.getMetaData(); int columnCount = meta.getColumnCount(); LinkedList<String> columns = new LinkedList<String>(); for (int i = 1; i < columnCount + 1; i++) { // We're only dealing with JSON, so the column names should be // JavaScript-friendly. columns.add(StringEscapeUtils.escapeJavaScript(meta.getColumnName(i))); } out.append("{\n \"columns\" : [ "); // Add column names in JSON format for (String column : columns) { out.append('"' + column + "\", "); } // remove the trailing ", " and add a line break and close the array len = out.length(); out.delete(len - 2, len); out.append(" ],\n"); // Add column values out.append(" \"results\" : [ \n"); for (int i = 0; i < limit && results.next(); i++) { out.append(rowAsJson(results, columns)); } // remove the trailing ", " len = out.length(); out.delete(len - 2, len); out.append("\n ]\n"); out.append("}"); return out.toString(); }
From source file:marytts.tools.dbselection.WikipediaMarkupCleaner.java
/*** * Internal links: /*from w w w . j av a2s . c o m*/ * [[Name of page]] * [[Name of page|Text to display]] * External links: * [http://www.example.org Text to display] * [http://www.example.org] * http://www.example.org */ private StringBuffer processInternalAndExternalLinks(StringBuffer line) { int index1, index2, index3; StringBuffer linetmp = null; // for debugging boolean changed = false; if (debug) linetmp = new StringBuffer(line); // Internal links: while ((index1 = line.indexOf("[[")) >= 0) { changed = true; if ((index2 = line.indexOf("]]")) >= 0) { if ((index3 = line.indexOf("|", index1)) >= 0 && index3 < index2) { // if there is text to display line.delete(index1, index3 + 1); // delete the link and [[ ]] index2 = line.indexOf("]]"); // since i delete some text i need to find again the next ]] line.delete(index2, index2 + 2); } else { line.delete(index1, index1 + 2); // delete the [[ index2 = line.indexOf("]]"); // since i delete some text i need to find again the next ]] line.delete(index2, index2 + 2); // delete the ]] -2 because in the previous line i deleted two chars } //if(debug) // System.out.println("LINE (AFTER): " + line); } else { if (debug) { System.out.println("processInternalAndExternalLinks: WARNING no ]] tag in " + line); System.out.println("deleting [["); } line.delete(index1, index1 + 2); // delete the [[ } } // External links: just the ones started with [http: and here I am deleting the whole reference // i am not keeping the text to display of this link. while ((index1 = line.indexOf("[http:")) >= 0 || (index1 = line.indexOf("[https:")) >= 0) { //System.out.println("LINE(BEFORE): " + line); if ((index2 = line.indexOf("]", index1)) >= 0) { // line.delete(index1, index2+1); if ((index3 = line.indexOf(" ", index1)) >= 0 && index3 < index2) { // if there is text to display line.delete(index1, index3 + 1); // delete the link and [http: until first black space before ] index2 = line.indexOf("]"); // since i delete some text i need to find again the next ]] line.delete(index2, index2 + 1); } else { line.delete(index1, index2 + 1); // no text to display, delete the whole ref } //System.out.println("LINE (AFTER): " + line + "\n"); } else { if (debug) { System.out.println( "processInternalAndExternalLinks: WARNING no ] tag when processing lines with http: line=" + line); System.out.println("deleting ["); } line.delete(index1, index1 + 1); // delete the [ } } if (debug && changed) { System.out.println("Removing links, LINE(BEFORE): " + linetmp); System.out.println(" LINE (AFTER): " + line); } return line; }
From source file:it.cnr.icar.eric.server.common.Utility.java
/** * Removes the <?xml version="1.0"?> decalaration from XML string * @return the XML declaration// w w w .j a v a2 s .c o m */ public String removeXMLDeclaration(StringBuffer str) { String decl = ""; int len = str.length(); int startIndex = -1; //start of what we are removing int endIndex = -1; //end of what we are removing for (int i = 0; i < len; i++) { if (str.charAt(i) == '<') { decl += "<"; startIndex = i; //Skip spaces after '<' i++; while (str.charAt(i) == ' ') { decl += " "; i++; } if (str.charAt(i) == '?') { //We have an XML declaration to remove //Skip forward and find matching '>' while (str.charAt(i) != '>') { decl += str.charAt(i); i++; } decl += ">"; endIndex = i; break; } else { //Not an XML declaration startIndex = -1; break; } } } if (startIndex != -1) { str.delete(startIndex, endIndex + 1); } return decl; }
From source file:de.marcelkapfer.morseconverter.MainActivity.java
public void encode(View view) { EditText editText = (EditText) findViewById(R.id.edit_message); StringBuffer message = new StringBuffer(editText.getText()); if (message.toString().endsWith(" ")) { message = message.deleteCharAt(message.length() - 1); }/*from w ww . j a v a 2 s. c om*/ // Variables String input; StringBuffer output = new StringBuffer(); input = message.toString().toUpperCase() + "#"; StringBuffer inputToSign = new StringBuffer(input); while (!inputToSign.toString().equals("#")) { int d = 0; boolean signFull = true; StringBuffer sign = new StringBuffer(); while (signFull) { if (inputToSign.toString().charAt(d) == '+' || inputToSign.toString().charAt(d) == '#') { if (d == 0) { if (inputToSign.toString().startsWith("+")) { output.append(" "); } inputToSign.deleteCharAt(0); } else { sign.replace(0, sign.length(), inputToSign.toString().substring(0, d)); inputToSign.delete(0, d); signFull = false; } } else { d++; } } if (input.equals("")) { break; } else if (sign.toString().equals("01")) { output.append("A"); } else if (sign.toString().equals("1000")) { output.append("B"); } else if (sign.toString().equals("1010")) { output.append("C"); } else if (sign.toString().equals("100")) { output.append("D"); } else if (sign.toString().equals("0")) { output.append("E"); } else if (sign.toString().equals("0010")) { output.append("F"); } else if (sign.toString().equals("110")) { output.append("G"); } else if (sign.toString().equals("0000")) { output.append("H"); } else if (sign.toString().equals("00")) { output.append("I"); } else if (sign.toString().equals("0111")) { output.append("J"); } else if (sign.toString().equals("101")) { output.append("K"); } else if (sign.toString().equals("0100")) { output.append("L"); } else if (sign.toString().equals("11")) { output.append("M"); } else if (sign.toString().equals("10")) { output.append("N"); } else if (sign.toString().equals("111")) { output.append("O"); } else if (sign.toString().equals("0110")) { output.append("P"); } else if (sign.toString().equals("1101")) { output.append("Q"); } else if (sign.toString().equals("010")) { output.append("R"); } else if (sign.toString().equals("000")) { output.append("S"); } else if (sign.toString().equals("1")) { output.append("T"); } else if (sign.toString().equals("001")) { output.append("U"); } else if (sign.toString().equals("0001")) { output.append("V"); } else if (sign.toString().equals("011")) { output.append("W"); } else if (sign.toString().equals("1001")) { output.append("X"); } else if (sign.toString().equals("1011")) { output.append("Y"); } else if (sign.toString().equals("1100")) { output.append("Z"); } else if (sign.toString().equals("11111")) { output.append("0 (zero)"); } else if (sign.toString().equals("01111")) { output.append("1"); } else if (sign.toString().equals("00111")) { output.append("2"); } else if (sign.toString().equals("00011")) { output.append("3"); } else if (sign.toString().equals("00001")) { output.append("4"); } else if (sign.toString().equals("00000")) { output.append("5"); } else if (sign.toString().equals("10000")) { output.append("6"); } else if (sign.toString().equals("11000")) { output.append("7"); } else if (sign.toString().equals("11100")) { output.append("8"); } else if (sign.toString().equals("11110")) { output.append("9"); } else if (sign.toString().equals("0101")) { output.append(""); } else if (sign.toString().equals("1110")) { output.append(""); } else if (sign.toString().equals("0011")) { output.append(""); } else if (sign.toString().equals("00011000")) { output.append(""); } else if (sign.toString().equals("1111")) { output.append("CH"); } else if (sign.toString().equals("010101")) { output.append("."); } else if (sign.toString().equals("110011")) { output.append(","); } else if (sign.toString().equals("111000")) { output.append(":"); } else if (sign.toString().equals("101010")) { output.append(";"); } else if (sign.toString().equals("001100")) { output.append("?"); } else if (sign.toString().equals("101011")) { output.append("!"); } else if (sign.toString().equals("100001")) { output.append("-"); } else if (sign.toString().equals("001101")) { output.append("_"); } else if (sign.toString().equals("10110")) { output.append("("); } else if (sign.toString().equals("101101")) { output.append(")"); } else if (sign.toString().equals("011110")) { output.append("'"); } else if (sign.toString().equals("10001")) { output.append("="); } else if (sign.toString().equals("01010")) { output.append("+ or End of the signal"); } else if (sign.toString().equals("10010")) { output.append("/"); } else if (sign.toString().equals("011010")) { output.append("@"); } else if (sign.toString().equals("10101")) { output.append("Begin of the signal"); } else if (sign.toString().equals("10001")) { output.append("Wait"); } else if (sign.toString().equals("00010")) { output.append("Understood"); } else if (sign.toString().equals("000101")) { output.append("End of work"); } else if (sign.toString().equals("000111000")) { output.append("SOS"); } else if (sign.toString().equals("00000000")) { output.append("Error"); } else { tfOutput = "Code not listed or wrong."; } } tfOutput = output.toString(); lastFragment = 0; After(view); /*} catch (Exception e) { tfOutput.setText("Some error occured. I'm sorry!"); }*/ }
From source file:com.gst.organisation.teller.service.TellerManagementReadPlatformServiceImpl.java
private String getTellerCriteria(final String sqlSearch, final Long officeId, final String status) { final StringBuffer extraCriteria = new StringBuffer(200); if (sqlSearch != null) { extraCriteria.append(" and (").append(sqlSearch).append(")"); }/*from w w w.j av a 2 s . c om*/ if (officeId != null) { extraCriteria.append(" and office_id = ").append(officeId).append(" "); } // Passing status parameter to get ACTIVE (By Default), INACTIVE or ALL // (Both active and Inactive) employees if (status.equalsIgnoreCase("active")) { extraCriteria.append(" and status = 300 "); } else if (status.equalsIgnoreCase("inActive")) { extraCriteria.append(" and status = 0 "); } else if (status.equalsIgnoreCase("all")) { } else { throw new UnrecognizedQueryParamException("status", status, new Object[] { "all", "active", "inactive" }); } if (StringUtils.isNotBlank(extraCriteria.toString())) { extraCriteria.delete(0, 4); } // remove begin four letter including a space from the string. return extraCriteria.toString(); }
From source file:com.shouxun.server.netty.tcp.EchoServerHandler.java
public void execuseDate(String data, ChannelHandlerContext ctx) { if (data == null || data.equals("") || data.length() < 8) { return;/*from w w w. j a v a 2 s . c o m*/ } String[] datas = StringUtil.split(data.replaceAll("\\[", "").replaceAll("\\]", "").trim(), ','); String requestCode = datas[8].trim(); String imei = datas[6].trim(); System.out.println("server channelRead...questCode=" + requestCode + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); StringBuffer sb = new StringBuffer(); if (!data.contains("]")) { if (datas.length > 9 && datas[9].length() > 14) { //?? sb.delete(0, sb.length()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S911").append(",").append("0").append("]"); if (hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } } return; } //ip????? /*if(null != hashMapClient && hashMapClient.get(imei) != null){ hashMapClient.put(imei, ctx); }*/ switch (requestCode) { case "T1":// T1/S1 hashMapClient.put(imei, ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(datas[9]) .append(",").append("S1").append(",").append("1").append(",").append(getGMT(datas[7].trim())) .append(",").append("]"); sendMsg(sb.toString(), ctx); System.out.println("server channelWrite...S1=" + sb.toString() + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); break; case "T2"://T2/S2 hashMapClient.put(imei, ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S2").append("]"); sendMsg(sb.toString(), ctx); System.out.println("server channelWrite...S2=" + sb.toString() + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); break; case "T5"://??,S5/T5 //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T5,imei?] //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2014-11-28 13:40:20,1-1,460021581801906,8,T5,355372020827303 //??? System.out.println("server channelRead...T5" + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S112").append(",").append("1").append("]"); if (datas.length > 9 && hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } break; case "T7"://??? //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T7,imei] System.out.println("server channelRead...T7" + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S113").append(",").append("1").append("]"); if (datas.length > 9 && hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } break; case "T10": //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-1,355372020827303,8,T10,imei?] //??? System.out.println("server channelRead...T10" + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S114").append(",").append("1").append("]"); if (datas.length > 9 && hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } break; case "T11"://? //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T11,imei] System.out.println("server channelRead...T11" + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S115").append(",").append("1").append("]"); if (datas.length > 9 && hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } break; case "T13": //??? System.out.println("server channelRead...T13" + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S116").append(",").append("1").append("]"); if (datas.length > 9 && hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } break; case "T15"://GPS? System.out.println("server channelRead...T15" + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T15,imei] sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S117").append(",").append("1").append("]"); if (datas.length > 9 && hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } break; case "T18": System.out.println("server channelRead...T18" + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S118").append(",").append("1").append("]"); if (datas.length > 9 && hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } break; case "T19": System.out.println("server channelRead...T19" + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S119").append(",").append("1").append("]"); if (datas.length > 9 && hashMapClient.get(datas[9].trim()) != null) { sendMsg(sb.toString(), hashMapClient.get(datas[9].trim())); } break; case "T28"://???(T28/S28) //[V1.0.0,a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T28, imei?,mt_pulse,118, 1267511609] //???? hashMapClient.put(imei, ctx); Pulse pulse = new Pulse(); try { pulse.setImei(imei); pulse.setDataType(datas[10]); pulse.setPulseCount(Integer.valueOf(datas[11])); pulseService.save(pulse); } catch (Exception e) { e.printStackTrace(); } //S28 //[v1.0.0, a1d83kdeio3fg33k,1,d961,2013-08-07 00:12:52,123456789012345,S28] sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S28").append("]"); sendMsg(sb.toString(), ctx); System.out.println("server channelWrite...S28=" + sb.toString() + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); //?? if (!(datas[9] == null || datas[9].equals(""))) { sb.delete(0, sb.length()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S112").append(",").append("2").append(",") .append(datas[10]).append(",").append(datas[11]).append(",").append(datas[12]).append("]"); sendMsg(sb.toString(), hashMapClient.get(datas[9])); } break; case "T29": hashMapClient.put(imei, ctx); //S29 //[v1.0.0, a1d83kdeio3fg33k,1,d961,2013-08-07 00:12:52,123456789012345,S28] sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S29").append("]"); sendMsg(sb.toString(), ctx); System.out.println("server channelWrite...S29=" + sb.toString() + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); //???? //[V1.0.0,a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00, 1-2,355372020827303,8,T29, imei?,GPS_AT, 114.356170, 34.824230, count$1$0|28725|18784,20,30,40,1267511609] double x = 0; double y = 0; PointDouble newpt = null; String url = ""; String type = ""; //GPS?LBS????? if ((datas[11] != null && !datas[11].equals("")) && (datas[12] != null && !datas[12].equals(""))) { //GPS? x = Double.valueOf(datas[11]);//? y = Double.valueOf(datas[12]);// type = "GPS"; TrackRoute trackRoute = new TrackRoute(); trackRoute.setImei(datas[6]); ModifyOffset mo; try { mo = ModifyOffset .getInstance(TrackDataServerHandler.class.getResourceAsStream("/axisoffset.dat")); PointDouble pt = new PointDouble(x, y); newpt = mo.s2c(pt); trackRoute.setLongitude(newpt.x); trackRoute.setLatitude(newpt.y); trackRoute.setLocationType("GPS"); trackRouteService.save(trackRoute); } catch (Exception e) { e.printStackTrace(); } } else { //LBS? //[V1.0.0,31,1,abcd,2015-01-26 14:45:38,1-4,866161010000076,0,T29,,GPS_SOS,121.3927350,31.1634062,mcount$5$460$0$0#1806|1231|0|36#1806|3292|0|27#1806|1241|0|25#1806|1232|0|25#1806|2183|0|26,0,0,0,1422254738] //http://minigps.net/as?x=460-0-1806-1231-92-1806-2183-8d-1806-1241-87-1806-3292-8b-1806-21b2-8d-1806-2123-8f &p=1&mt&ta&needaddress //http://minigps.net/as?x=1cc-0-18be-9f22-95-18be-9121-7b-18be-91e2-76-18be-9122-76-18c2-f2b1-74-18cc-f412-79 &ta=0&p=1&mt=0&needaddress=0 type = "LBS"; url = "http://minigps.net/as?x="; String[] params = datas[13].trim().split("\\$"); url += Integer.toHexString(Integer.valueOf(params[2])) + "-" + Integer.toHexString(Integer.valueOf(params[3])); String[] lbs = params[4].split("#"); String[] lbsParam; for (int i = 1; i < lbs.length; i++) { lbsParam = lbs[i].split("\\|"); url += "-" + lbsParam[0]; url += "-" + lbsParam[1]; url += "-" + Integer.toHexString(Integer.valueOf(Integer.valueOf(lbsParam[3]) + 110)); } url += "&ta=0&p=1&mt=0&needaddress=0"; System.out.println("get LBS url=" + url); // (1) HttpGet HttpGet get = new HttpGet(url); // (2) HttpClient??getHttpResponse HttpClient http = new DefaultHttpClient(); HttpResponse response; InputStream in = null; try { response = http.execute(get); // (3) ? if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); in = entity.getContent(); String result = readString(in); System.out.println("get LBS url result=" + result); if (result != null && result.startsWith("{")) { JSONObject jsonObject = JSONObject.fromObject(result); if (jsonObject.getInt("status") == 0) { x = jsonObject.getDouble("lon"); y = jsonObject.getDouble("lat"); TrackRoute trackRoute = new TrackRoute(); trackRoute.setImei(datas[6]); ModifyOffset mo; try { mo = ModifyOffset.getInstance( TrackDataServerHandler.class.getResourceAsStream("/axisoffset.dat")); PointDouble pt = new PointDouble(x, y); newpt = mo.s2c(pt); trackRoute.setLongitude(newpt.x); trackRoute.setLatitude(newpt.y); trackRoute.setLocationType("LBS"); trackRouteService.save(trackRoute); } catch (Exception e) { e.printStackTrace(); } } } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } //??,???????? if (!(datas[9] == null || datas[9].equals(""))) { sb.delete(0, sb.length()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S116").append(",").append("2").append(",") .append(null != newpt ? newpt.x : -1).append(",").append(null != newpt ? newpt.y : -1) .append(",").append(type).append("]"); sendMsg(sb.toString(), hashMapClient.get(datas[9])); } Bracelet bracelet = braceletService.get(imei); if (bracelet != null) { Set<Fence> fences = bracelet.getFences(); for (Fence fence : fences) { double distance = 0; distance = MapUtil.getDistance(y, x, fence.getLatitude(), fence.getLongitude()) - fence.getRadius(); DecimalFormat df = new DecimalFormat(".##"); if (distance > 0) { if (fence.getIsOutside() == 0) { fence.setIsOutside(1); fenceService.update(fence); for (Binding binding : bracelet.getBingdings()) { User user = binding.getUser(); JSONObject jsonObject = new JSONObject(); if (user.getDeivceType().equals("android") && user.getChannelID() != null && !user.getChannelID().equals("")) { String desc = "??[" + bracelet.getName() + "]" + df.format(distance) + ""; jsonObject.put("title", "????"); jsonObject.put("description", desc); jsonObject.put("open_type", 2); jsonObject.put("pkg_content", ""); BaiduPushUtil.androidPushNotification(user.getChannelID(), user.getUserID(), jsonObject.toString()); PushMessage pushMessage = new PushMessage(); pushMessage.setChannelID(user.getChannelID()); pushMessage.setDeivceType(user.getDeivceType()); pushMessage.setPhoneCode(user.getPhoneCode()); pushMessage.setTitle("????"); pushMessage.setMessage(desc); pushMessage.setType(0); pushMessageService.save(pushMessage); logger.info("?android?" + desc); } else if (user.getDeivceType().equals("iOS") && user.getChannelID() != null && !user.getChannelID().equals("")) { JSONObject js = new JSONObject(); String alert = "??[" + bracelet.getName() + "]" + df.format(distance) + ""; js.put("alert", alert); jsonObject.put("aps", js); BaiduPushUtil.iosPushNotification(user.getChannelID(), user.getUserID(), jsonObject.toString()); PushMessage pushMessage = new PushMessage(); pushMessage.setChannelID(user.getChannelID()); pushMessage.setDeivceType(user.getDeivceType()); pushMessage.setPhoneCode(user.getPhoneCode()); pushMessage.setTitle("????"); pushMessage.setMessage(alert); pushMessage.setType(0); pushMessageService.save(pushMessage); logger.info("?iOS?" + alert); } } } break; } else { if (fence.getIsOutside() == 1) { fence.setIsOutside(0); fenceService.update(fence); } } } } break; case "T30"://?(T30/S30) hashMapClient.put(imei, ctx); //[V1.0.0,460026734416459,1,6042,2014-04-10 08:00:47,1-1,356511170016386,8,T30,imei?,step,1,76,386,0,1,1397001635] //S30 //[v1.0.0, a1d83kdeio3fg33k,1,d961,2013-08-07 00:12:52,123456789012345,S30] sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S30").append("]"); sendMsg(sb.toString(), ctx); System.out.println("server channelWrite...S30=" + sb.toString() + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); //???? Step step = new Step(); step.setImei(imei); step.setDataType(datas[10]); step.setNumber(Integer.valueOf(datas[11])); step.setTotalSteps(Integer.valueOf(datas[12])); step.setTotalDis(datas[13]); step.setCalories(datas[14]); step.setFlag(Integer.valueOf(datas[15])); stepService.save(step); //sleep Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.set(Calendar.HOUR_OF_DAY, 8); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); Date endTime = c.getTime(); Calendar c1 = Calendar.getInstance(); c1.setTime(new Date()); c1.add(c1.DATE, -1); c1.set(Calendar.HOUR_OF_DAY, 22); c1.set(Calendar.MINUTE, 00); c1.set(Calendar.SECOND, 00); Date startTime = c1.getTime(); List<Step> list = stepService.getStepByDate(imei, startTime, endTime); //??? int time_period = 10;//10 int over_deep_value = Constant.OVER_DEEP_VALUE; int over_shallow_value = Constant.OVER_SHALLOW_VALUE; Step step1 = null; int totalsteps2 = 0; int deep_sleep_hour = 0;//10?,<=5 int shallow_sleep_hour = 0;//10?<=10 int zeor_count = 0;//0000 -8:00? for (int i = 0; i < list.size(); i++) { step1 = list.get(i); int totalsteps1 = step1.getTotalSteps(); int count = totalsteps1 - totalsteps2; if (count <= over_deep_value) { deep_sleep_hour += time_period; } else if (over_deep_value < count && count <= over_shallow_value) { shallow_sleep_hour += time_period; } totalsteps2 = totalsteps1; if (i >= 12 && totalsteps1 == 0) { zeor_count++; } } int wear = 0; int total_sleep = 0; int deep_sleep = 0; int shallow_sleep = 0; if (zeor_count > 40) { wear = 0; total_sleep = 0; deep_sleep = 0; shallow_sleep = 0; } else { wear = 1; total_sleep = deep_sleep_hour + shallow_sleep_hour; deep_sleep = deep_sleep_hour; shallow_sleep = shallow_sleep_hour; } //?? if (!(datas[9] == null || datas[9].equals(""))) { sb.delete(0, sb.length()); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S114").append(",").append("2").append(",") .append(datas[10]).append(",").append(datas[11]).append(",").append(datas[12]).append(",") .append(total_sleep).append(",").append(deep_sleep).append(",").append(shallow_sleep) .append(",").append(wear).append("]"); sendMsg(sb.toString(), hashMapClient.get(datas[9])); } break; case "T34": //[V1.0.0,a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00, 1-2,355372020827303,8,T34, ,voltage,1,1267511609] Bracelet baterry_bracelet = braceletService.get(imei); baterry_bracelet.setBattery(datas[11]); braceletService.update(baterry_bracelet); hashMapClient.put(imei, ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S34").append("]"); sendMsg(sb.toString(), ctx); System.out.println("server channelWrite...S34=" + sb.toString() + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); break; case "T47": //[V1.0.0,a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00, 1-2,355372020827303,8,T47,,wear,1,1267511609] Bracelet wear_bracelet = braceletService.get(imei); wear_bracelet.setWear(datas[11]); braceletService.update(wear_bracelet); hashMapClient.put(imei, ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]).append(",") .append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",").append(imei) .append(",").append("S47").append("]"); sendMsg(sb.toString(), ctx); System.out.println("server channelWrite...S47=" + sb.toString() + " imei=" + imei + " localAddress=" + ctx.channel().localAddress() + " remoteAddress=" + ctx.channel().remoteAddress()); //?? for (Binding binding : wear_bracelet.getBingdings()) { User user = binding.getUser(); JSONObject jsonObject = new JSONObject(); if (user.getDeivceType().equals("android") && user.getChannelID() != null && !user.getChannelID().equals("")) { String desc = "??[" + wear_bracelet.getName() + "]" + (Integer.valueOf(datas[11]) == 0 ? "" : "?"); jsonObject.put("title", "??"); jsonObject.put("description", desc); //jsonObject.put("open_type", 2); //jsonObject.put("pkg_content", ""); BaiduPushUtil.androidPushNotification(user.getChannelID(), user.getUserID(), jsonObject.toString()); PushMessage pushMessage = new PushMessage(); pushMessage.setChannelID(user.getChannelID()); pushMessage.setDeivceType(user.getDeivceType()); pushMessage.setPhoneCode(user.getPhoneCode()); pushMessage.setTitle("??"); pushMessage.setMessage(desc); pushMessage.setType(1); pushMessageService.save(pushMessage); logger.info("?android?" + desc); } else if (user.getDeivceType().equals("iOS") && user.getChannelID() != null && !user.getChannelID().equals("")) { JSONObject js = new JSONObject(); String alert = "??[" + wear_bracelet.getName() + "]" + (Integer.valueOf(datas[11]) == 0 ? "" : "?"); js.put("alert", alert); jsonObject.put("aps", js); BaiduPushUtil.iosPushNotification(user.getChannelID(), user.getUserID(), jsonObject.toString()); PushMessage pushMessage = new PushMessage(); pushMessage.setChannelID(user.getChannelID()); pushMessage.setDeivceType(user.getDeivceType()); pushMessage.setPhoneCode(user.getPhoneCode()); pushMessage.setTitle("??"); pushMessage.setMessage(alert); pushMessage.setType(1); pushMessageService.save(pushMessage); logger.info("?iOS?" + alert); } } break; case "T112"://??,imei? //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T112,?imei] //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,460021581801906,8,T112,355372020827303] if (hashMapClient.get(imei) == null) { //?? sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S112").append(",").append("0").append("]"); sendMsg(sb.toString(), ctx); } else { //? hashMapClient.put(datas[9].trim(), ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S5").append(",").append(datas[9]).append("]"); sendMsg(sb.toString(), hashMapClient.get(imei)); System.out.println("server channelWrite...S5=" + sb.toString() + " imei=" + imei + " localAddress=" + hashMapClient.get(imei).channel().localAddress() + " remoteAddress=" + hashMapClient.get(imei).channel().remoteAddress()); } break; case "T113"://??,imei???180 //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T113,imei?,300] //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,460021581801906,8,T113,355372020827303] if (hashMapClient.get(imei) == null) { //??? sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S113").append(",").append("0").append("]"); sendMsg(sb.toString(), ctx); } else { //? //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,355372020827303,S7,imei?,300] hashMapClient.put(datas[9].trim(), ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S7").append(",").append(datas[9]).append(",") .append(datas[10]).append("]"); sendMsg(sb.toString(), hashMapClient.get(imei)); System.out.println("server channelWrite...S7=" + sb.toString() + " imei=" + imei + " localAddress=" + hashMapClient.get(imei).channel().localAddress() + " remoteAddress=" + hashMapClient.get(imei).channel().remoteAddress()); Bracelet b = braceletService.get(imei); b.setUploadPulseRate(datas[10]); braceletService.update(b); } break; case "T114":// if (hashMapClient.get(imei) == null) { //?? sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S114").append(",").append("0").append("]"); sendMsg(sb.toString(), ctx); } else { //? hashMapClient.put(datas[9].trim(), ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S10").append(",").append(datas[9]).append("]"); sendMsg(sb.toString(), hashMapClient.get(imei)); System.out.println("server channelWrite...S10=" + sb.toString() + " imei=" + imei + " localAddress=" + hashMapClient.get(imei).channel().localAddress() + " remoteAddress=" + hashMapClient.get(imei).channel().remoteAddress()); } break; case "T115"://,imei???180 //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T115,imei?,300] if (hashMapClient.get(imei) == null) { //??? sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S115").append(",").append("0").append("]"); sendMsg(sb.toString(), ctx); } else { //? (S11/T11) //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,355372020827303,S7,imei?,300] hashMapClient.put(datas[9].trim(), ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S11").append(",").append(datas[9]).append(",") .append(datas[10]).append("]"); sendMsg(sb.toString(), hashMapClient.get(imei)); System.out.println("server channelWrite...S11=" + sb.toString() + " imei=" + imei + " localAddress=" + hashMapClient.get(imei).channel().localAddress() + " remoteAddress=" + hashMapClient.get(imei).channel().remoteAddress()); Bracelet b = braceletService.get(imei); b.setUploadStepRate(datas[10]); braceletService.update(b); } break; case "T116"://GPS if (hashMapClient.get(imei) == null) { //?? sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S116").append(",").append("0").append("]"); sendMsg(sb.toString(), ctx); } else { //? hashMapClient.put(datas[9].trim(), ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S13").append(",").append(datas[9]).append("]"); sendMsg(sb.toString(), hashMapClient.get(imei)); System.out.println("server channelWrite...S13=" + sb.toString() + " imei=" + imei + " localAddress=" + hashMapClient.get(imei).channel().localAddress() + " remoteAddress=" + hashMapClient.get(imei).channel().remoteAddress()); } break; case "T117"://GPS,imei???180 //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,1-2,355372020827303,8,T115,imei?,300] if (hashMapClient.get(imei) == null) { //??? sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S117").append(",").append("0").append("]"); sendMsg(sb.toString(), ctx); } else { //? (S11/T11) //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,355372020827303,S7,imei?,300] hashMapClient.put(datas[9].trim(), ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S15").append(",").append(datas[9]).append(",") .append(datas[10]).append("]"); sendMsg(sb.toString(), hashMapClient.get(imei)); System.out.println("server channelWrite...S15=" + sb.toString() + " imei=" + imei + " localAddress=" + hashMapClient.get(imei).channel().localAddress() + " remoteAddress=" + hashMapClient.get(imei).channel().remoteAddress()); Bracelet b = braceletService.get(imei); b.setUploadGpsRate(datas[10]); braceletService.update(b); } break; case "T118"://SOS,imei? if (hashMapClient.get(imei) == null) { //??? sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S118").append(",").append("0").append("]"); sendMsg(sb.toString(), ctx); } else { //? (S11/T11) //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,355372020827303,S7,imei?,sos??] hashMapClient.put(datas[9].trim(), ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S18").append(",").append(datas[9]).append(",") .append(datas[10]).append("]"); sendMsg(sb.toString(), hashMapClient.get(imei)); System.out.println("server channelWrite...S18=" + sb.toString() + " imei=" + imei + " localAddress=" + hashMapClient.get(imei).channel().localAddress() + " remoteAddress=" + hashMapClient.get(imei).channel().remoteAddress()); Bracelet b = braceletService.get(imei); if (b != null) { b.setSosPhoneCode(datas[10]); braceletService.update(b); } } break; case "T119"://?,imei? if (hashMapClient.get(imei) == null) { //??? sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S119").append(",").append("0").append("]"); sendMsg(sb.toString(), ctx); } else { //? (S11/T11) //[V1.0.0, a1d83kdeio3fg33k,1,abcd,2011-12-15 10:00:00,355372020827303,S7,imei?,??] hashMapClient.put(datas[9].trim(), ctx); sb.append("[").append(datas[0]).append(",").append(datas[1]).append(",").append(datas[2]) .append(",").append(datas[3]).append(",").append(getGMT(datas[7].trim())).append(",") .append(imei).append(",").append("S19").append(",").append(datas[9]).append(",") .append(datas[10]).append("]"); sendMsg(sb.toString(), hashMapClient.get(imei)); System.out.println("server channelWrite...S19=" + sb.toString() + " imei=" + imei + " localAddress=" + hashMapClient.get(imei).channel().localAddress() + " remoteAddress=" + hashMapClient.get(imei).channel().remoteAddress()); Bracelet b = braceletService.get(imei); if (b != null) { b.setFamilyPhoneCode(datas[10]); braceletService.update(b); } } break; default: break; } }
From source file:tufts.vue.RichTextBox.java
private String stripHTMLTags(String message) { StringBuffer returnMessage = new StringBuffer(message); int startPosition = message.indexOf("<"); // encountered the first opening brace int endPosition = message.indexOf(">"); // encountered the first closing braces while (startPosition != -1) { returnMessage.delete(startPosition, endPosition + 1); // remove the tag startPosition = (returnMessage.toString()).indexOf("<"); // look for the next opening brace endPosition = (returnMessage.toString()).indexOf(">"); // look for the next closing brace }//w w w . ja v a 2 s . c o m return org.apache.commons.lang.StringEscapeUtils.unescapeHtml(returnMessage.toString().trim()); }