[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/bridge UnSerializer.java, NONE, 1.1
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/bridge In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31741/src/net/sourceforge/bprocessor/model/bridge Modified Files: Sensor.java DeSerializer.java Serializer.java DataItem.java Mote.java Added Files: UnSerializer.java Log Message: Sensors --- NEW FILE: UnSerializer.java --- //--------------------------------------------------------------------------------- // $Id: UnSerializer.java,v 1.1 2009/02/04 15:09:52 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model.bridge; import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; /** * */ public class UnSerializer { private InputStream input; /** * * @param input InputStream */ public UnSerializer(InputStream input) { this.input = input; } /** * * @return byte * @throws IOException IOException */ public byte readByte() throws IOException { byte value = (byte) input.read(); return value; } /** * * @return int * @throws IOException IOException */ public int readInt() throws IOException { int value = 0; int b1 = readByte(); int b2 = readByte(); int b3 = readByte(); int b4 = readByte(); value |= 0xFF & (b1 << 0); value |= 0xFF00 & (b2 << 8); value |= 0xFF0000 & (b3 << 16); value |= 0xFF000000 & (b4 << 24); return value; } /** * * @return byte[] * @throws IOException IOException */ public byte[] readBytes() throws IOException { int length = readInt(); byte[] bytes = new byte[length]; for (int i = 0; i < length; i++) { bytes[i] = readByte(); } return bytes; } /** * * @return String * @throws IOException IOException */ public String readString() throws IOException { return new String(readBytes()); } /** * * @return BigInteger * @throws IOException IOException */ public BigInteger readBigInteger() throws IOException { return new BigInteger(readBytes()); } } Index: Mote.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/bridge/Mote.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Mote.java 22 Sep 2008 15:58:09 -0000 1.1 --- Mote.java 4 Feb 2009 15:09:52 -0000 1.2 *************** *** 23,27 **** private List<DataItem> items; private long lasttime; ! /** * --- 23,27 ---- private List<DataItem> items; private long lasttime; ! /** * *************** *** 33,37 **** lasttime = 0; } ! /** * --- 33,45 ---- lasttime = 0; } ! ! /** ! * ! * @return id ! */ ! public long id() { ! return id; ! } ! /** * *************** *** 47,54 **** } /** {@inheritDoc} */ @Override public void delete() { ! } --- 55,81 ---- } + /** + * + * @param item DataItem + */ + public void add(DataItem item) { + if (item.timestamp() > lasttime) { + items.add(item); + lasttime = item.timestamp(); + } + } + + /** + * + * @return data items + */ + public List<DataItem> items() { + return items; + } + /** {@inheritDoc} */ @Override public void delete() { ! } *************** *** 70,74 **** public void setAttributes(List<Attribute> attributes) { // TODO Auto-generated method stub ! } --- 97,101 ---- public void setAttributes(List<Attribute> attributes) { // TODO Auto-generated method stub ! } Index: DeSerializer.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/bridge/DeSerializer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DeSerializer.java 22 Sep 2008 15:58:09 -0000 1.1 --- DeSerializer.java 4 Feb 2009 15:09:52 -0000 1.2 *************** *** 54,58 **** */ public String readString() { - readByte(); int length = readInt(); StringBuffer buffer = new StringBuffer(length); --- 54,57 ---- Index: Sensor.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/bridge/Sensor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Sensor.java 22 Sep 2008 15:58:09 -0000 1.1 --- Sensor.java 4 Feb 2009 15:09:52 -0000 1.2 *************** *** 8,15 **** --- 8,17 ---- package net.sourceforge.bprocessor.model.bridge; + import java.io.IOException; import java.util.LinkedList; import java.util.List; import net.sourceforge.bprocessor.model.Entity; + import net.sourceforge.bprocessor.model.Project; /** *************** *** 60,62 **** --- 62,83 ---- return "Motes"; } + + /** + * + */ + public void update() { + for (Mote current : motes) { + long id = current.id(); + try { + DataItem item = Project.latest((int)id); + if (item != null) { + current.add(item); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + Project.getInstance().changed(this); + } } Index: DataItem.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/bridge/DataItem.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DataItem.java 22 Sep 2008 15:58:09 -0000 1.1 --- DataItem.java 4 Feb 2009 15:09:52 -0000 1.2 *************** *** 8,15 **** package net.sourceforge.bprocessor.model.bridge; /** * */ ! public class DataItem { private int id; private long timestamp; --- 8,23 ---- package net.sourceforge.bprocessor.model.bridge; + import java.util.Date; + import java.util.LinkedList; + import java.util.List; + + import net.sourceforge.bprocessor.model.Attribute; + import net.sourceforge.bprocessor.model.Entity; + import net.sourceforge.bprocessor.model.Parametric; + /** * */ ! public class DataItem extends Entity implements Parametric { private int id; private long timestamp; *************** *** 38,40 **** --- 46,80 ---- return timestamp; } + + /** {@inheritDoc} */ + @Override + public void delete() { + // TODO Auto-generated method stub + + } + + /** {@inheritDoc} */ + public List<Attribute> getAttributes() { + return new LinkedList(); + } + + /** {@inheritDoc} */ + public void setAttributes(List<Attribute> attributes) { + // TODO Auto-generated method stub + + } + + /** {@inheritDoc} */ + public String title() { + // TODO Auto-generated method stub + return "Data"; + } + + /** + * {@inheritDoc} + */ + public String getName() { + Date date = new Date(timestamp); + return date + " | " + data; + } } Index: Serializer.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/bridge/Serializer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Serializer.java 22 Sep 2008 15:58:09 -0000 1.1 --- Serializer.java 4 Feb 2009 15:09:52 -0000 1.2 *************** *** 6,15 **** //--------------------------------------------------------------------------------- - package net.sourceforge.bprocessor.model.bridge; import java.io.IOException; import java.io.OutputStream; ! /** --- 6,14 ---- //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model.bridge; import java.io.IOException; import java.io.OutputStream; ! import java.math.BigInteger; /** *************** *** 18,23 **** public class Serializer { private OutputStream output; /** - * * @param output OutputStream */ --- 17,22 ---- public class Serializer { private OutputStream output; + /** * @param output OutputStream */ *************** *** 25,73 **** this.output = output; } - /** - * * @param value byte */ ! public void writeByte(byte value) { ! try { ! output.write(value); ! } catch (IOException e) { ! // empty ! } } /** - * * @param value int */ ! public void writeInt(int value) { ! writeByte((byte) (value >> 0)); ! writeByte((byte) (value >> 8)); ! writeByte((byte) (value >> 16)); ! writeByte((byte) (value >> 24)); } /** ! * ! * @param value String */ ! public void writeString(String value) { ! int length = value.length(); ! writeByte((byte) 0); ! writeInt(length); ! for (int index = 0; index < length; index++) { ! writeByte((byte) value.charAt(index)); } - writeByte((byte) 0); } /** ! * ! * @param buffer bytes */ ! public void writeBuffer(byte[] buffer) { ! int length = buffer.length; ! writeInt(length); ! for (int index = 0; index < length; index++) { ! writeByte(buffer[index]); ! } } } --- 24,71 ---- this.output = output; } /** * @param value byte + * @throws IOException IOException */ ! public void writeByte(byte value) throws IOException { ! output.write((int) value); } /** * @param value int + * @throws IOException IOException */ ! public void writeInt(int value) throws IOException { ! byte b1 = (byte) ((value >> 0) & 0xFF); ! byte b2 = (byte) ((value >> 8) & 0xFF); ! byte b3 = (byte) ((value >> 16) & 0xFF); ! byte b4 = (byte) ((value >> 24) & 0xFF); ! writeByte(b1); ! writeByte(b2); ! writeByte(b3); ! writeByte(b4); } /** ! * @param value byte[] ! * @throws IOException IOException */ ! public void writeBytes(byte[] value) throws IOException { ! writeInt(value.length); ! for (int i = 0; i < value.length; i++) { ! writeByte((byte) value[i]); } } /** ! * @param value String ! * @throws IOException IOException */ ! public void writeString(String value) throws IOException { ! writeBytes(value.getBytes()); ! } ! /** ! * @param value BigInteger ! * @throws IOException IOException ! */ ! public void writeBigInteger(BigInteger value) throws IOException { ! writeBytes(value.toByteArray()); } } |