Skip to content

Commit d6b755f

Browse files
committed
Merge pull request #8 from MD2Korg/KryoUpdate
Kryo update
2 parents 10c2e47 + 74b3235 commit d6b755f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+383
-417
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ dependencies {
3636
compile 'org.apache.httpcomponents:httpclient:4.5'
3737
compile 'org.apache.httpcomponents:fluent-hc:4.5'
3838
compile 'org.apache.httpcomponents:httpmime:4.5'
39-
39+
compile 'com.esotericsoftware:kryo:3.0.3'
4040
}
41+

src/main/java/org/md2k/cerebralcortex/StudyInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
public class StudyInfo {
2929

30-
public String study_id;
31-
public String study_name;
30+
public String id;
31+
public String name;
3232

3333
public StudyInfo() {
3434

src/main/java/org/md2k/dataexporter/DataExport.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929

30+
import com.esotericsoftware.kryo.Kryo;
31+
import com.esotericsoftware.kryo.io.Input;
3032
import com.google.gson.Gson;
3133
import com.google.gson.GsonBuilder;
3234
import com.google.gson.stream.JsonWriter;
@@ -68,6 +70,8 @@ public class DataExport {
6870

6971
private Statement statement = null;
7072

73+
private Kryo kryo = new Kryo();
74+
7175
/**
7276
* Build a DataExport object that connects to a sqlite database file
7377
*
@@ -324,7 +328,7 @@ private StudyInfo getStudyInfo() {
324328
String[] json = DataTypeConverter.DataTypeToString(dt).split(",", 2);
325329
Gson gson = new GsonBuilder().setPrettyPrinting().create();
326330
StudyInfo si = gson.fromJson(json[1], StudyInfo.class);
327-
if (!si.study_id.isEmpty()) {
331+
if (!si.id.isEmpty()) {
328332
return si;
329333
}
330334

@@ -430,7 +434,8 @@ private DataSource getDataSource(Integer id) {
430434
ResultSet rs = statement.executeQuery("Select datasource from datasource where ds_id = " + id);
431435
while (rs.next()) {
432436
byte[] b = rs.getBytes("datasource");
433-
result = DataSource.fromBytes(b);
437+
Input input = new Input(new ByteArrayInputStream(b));
438+
result = (DataSource) kryo.readClassAndObject(input);
434439
}
435440
} catch (SQLException e) {
436441
e.printStackTrace();

src/main/java/org/md2k/dataexporter/SQLiteIterator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
2727

28+
import com.esotericsoftware.kryo.Kryo;
29+
import com.esotericsoftware.kryo.io.Input;
2830
import org.md2k.datakitapi.datatype.DataType;
2931

32+
import java.io.ByteArrayInputStream;
3033
import java.sql.ResultSet;
3134
import java.sql.SQLException;
3235
import java.sql.Statement;
@@ -38,6 +41,8 @@
3841
public class SQLiteIterator implements Iterator<List<DataType>> {
3942
private ResultSet rs;
4043
private int bufferSize;
44+
private Kryo kryo = new Kryo();
45+
4146
public SQLiteIterator(Statement statement, Integer id, int bufferSize) {
4247
this.bufferSize = bufferSize;
4348
try {
@@ -64,8 +69,11 @@ public List<DataType> next() {
6469
try {
6570
while (result.size() < bufferSize && rs.next()) {
6671
byte[] b = rs.getBytes("sample");
67-
DataType dt = DataType.fromBytes(b);
72+
Input input = new Input(new ByteArrayInputStream(b));
73+
DataType dt = (DataType) kryo.readClassAndObject(input);
6874
result.add(dt);
75+
76+
6977
}
7078
} catch (SQLException e) {
7179
e.printStackTrace();

src/main/java/org/md2k/datakitapi/Constants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@
2727
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929
public class Constants {
30-
public static final long serialVersionUID = 2L;
3130
}
Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package org.md2k.datakitapi.datatype;
22

3-
import org.md2k.datakitapi.Constants;
4-
import org.md2k.datakitapi.time.DateTime;
53

6-
import java.io.*;
4+
import org.md2k.datakitapi.time.DateTime;
75

8-
/**
6+
/*
97
* Copyright (c) 2015, The University of Memphis, MD2K Center
108
* - Syed Monowar Hossain <monowar.hossain@gmail.com>
119
* All rights reserved.
@@ -31,71 +29,20 @@
3129
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3230
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3331
*/
34-
public class DataType implements Serializable{
35-
private static final long serialVersionUID = Constants.serialVersionUID;
32+
public class DataType {
3633
long dateTime;
3734
long offset;
3835

3936
public DataType(long dateTime) {
4037
this.dateTime = dateTime;
4138
this.offset= DateTime.getTimeZoneOffset();
4239
}
43-
public long getDateTime() {
44-
return dateTime;
45-
}
4640

47-
public byte[] toBytes() {
48-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
49-
ObjectOutput out = null;
50-
try {
51-
out = new ObjectOutputStream(bos);
52-
out.writeObject(this);
53-
return bos.toByteArray();
54-
} catch (IOException e) {
55-
e.printStackTrace();
56-
} finally {
57-
try {
58-
if (out != null) {
59-
out.close();
60-
}
61-
} catch (IOException ex) {
62-
// ignore close exception
63-
}
64-
try {
65-
bos.close();
66-
} catch (IOException ex) {
67-
// ignore close exception
68-
}
69-
}
70-
return null;
41+
public DataType() {
7142
}
7243

73-
public static DataType fromBytes(byte[] dataSourceByteArray) {
74-
ByteArrayInputStream bis = new ByteArrayInputStream(dataSourceByteArray);
75-
DataType dataSource = null;
76-
ObjectInput in = null;
77-
try {
78-
in = new ObjectInputStream(bis);
79-
dataSource = (DataType) in.readObject();
80-
return dataSource;
81-
} catch (ClassNotFoundException e) {
82-
e.printStackTrace();
83-
} catch (IOException e) {
84-
e.printStackTrace();
85-
} finally {
86-
try {
87-
bis.close();
88-
} catch (IOException ex) {
89-
// ignore close exception
90-
}
91-
try {
92-
if (in != null) {
93-
in.close();
94-
}
95-
} catch (IOException ex) {
96-
// ignore close exception
97-
}
98-
}
99-
return null;
44+
45+
public long getDateTime() {
46+
return dateTime;
10047
}
10148
}

src/main/java/org/md2k/datakitapi/datatype/DataTypeBoolean.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package org.md2k.datakitapi.datatype;
22

3-
import java.io.Serializable;
43

5-
/**
4+
/*
65
* Copyright (c) 2015, The University of Memphis, MD2K Center
76
* - Syed Monowar Hossain <monowar.hossain@gmail.com>
87
* All rights reserved.
@@ -28,13 +27,18 @@
2827
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2928
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3029
*/
31-
public class DataTypeBoolean extends DataType implements Serializable{
30+
public class DataTypeBoolean extends DataType {
3231
boolean sample;
3332

3433
public DataTypeBoolean(long timestamp, boolean sample) {
3534
super(timestamp);
3635
this.sample=sample;
3736
}
37+
38+
public DataTypeBoolean() {
39+
}
40+
41+
3842
public boolean getSample(){
3943
return sample;
4044
}

src/main/java/org/md2k/datakitapi/datatype/DataTypeBooleanArray.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package org.md2k.datakitapi.datatype;
22

3-
import java.io.Serializable;
43

5-
/**
4+
/*
65
* Copyright (c) 2015, The University of Memphis, MD2K Center
76
* - Syed Monowar Hossain <monowar.hossain@gmail.com>
87
* All rights reserved.
9-
* <p/>
8+
*
109
* Redistribution and use in source and binary forms, with or without
1110
* modification, are permitted provided that the following conditions are met:
12-
* <p/>
11+
*
1312
* * Redistributions of source code must retain the above copyright notice, this
1413
* list of conditions and the following disclaimer.
15-
* <p/>
14+
*
1615
* * Redistributions in binary form must reproduce the above copyright notice,
1716
* this list of conditions and the following disclaimer in the documentation
1817
* and/or other materials provided with the distribution.
19-
* <p/>
18+
*
2019
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2120
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2221
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -28,14 +27,17 @@
2827
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2928
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3029
*/
31-
public class DataTypeBooleanArray extends DataType implements Serializable {
30+
public class DataTypeBooleanArray extends DataType {
3231
boolean[] sample;
3332

3433
public DataTypeBooleanArray(long timestamp, boolean[] sample) {
3534
super(timestamp);
3635
this.sample = sample;
3736
}
3837

38+
public DataTypeBooleanArray() {
39+
}
40+
3941
public boolean[] getSample() {
4042
return sample;
4143
}

src/main/java/org/md2k/datakitapi/datatype/DataTypeByte.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package org.md2k.datakitapi.datatype;
22

3-
import java.io.Serializable;
43

5-
/**
4+
/*
65
* Copyright (c) 2015, The University of Memphis, MD2K Center
76
* - Syed Monowar Hossain <monowar.hossain@gmail.com>
87
* All rights reserved.
9-
* <p/>
8+
*
109
* Redistribution and use in source and binary forms, with or without
1110
* modification, are permitted provided that the following conditions are met:
12-
* <p/>
11+
*
1312
* * Redistributions of source code must retain the above copyright notice, this
1413
* list of conditions and the following disclaimer.
15-
* <p/>
14+
*
1615
* * Redistributions in binary form must reproduce the above copyright notice,
1716
* this list of conditions and the following disclaimer in the documentation
1817
* and/or other materials provided with the distribution.
19-
* <p/>
18+
*
2019
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2120
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2221
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -28,14 +27,18 @@
2827
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2928
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3029
*/
31-
public class DataTypeByte extends DataType implements Serializable {
30+
public class DataTypeByte extends DataType {
3231
byte sample;
3332

3433
public DataTypeByte(long timestamp, byte sample) {
3534
super(timestamp);
3635
this.sample = sample;
3736
}
3837

38+
public DataTypeByte() {
39+
}
40+
41+
3942
public byte getSample() {
4043
return sample;
4144
}

src/main/java/org/md2k/datakitapi/datatype/DataTypeByteArray.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package org.md2k.datakitapi.datatype;
22

3-
import java.io.Serializable;
43

5-
/**
4+
/*
65
* Copyright (c) 2015, The University of Memphis, MD2K Center
76
* - Syed Monowar Hossain <monowar.hossain@gmail.com>
87
* All rights reserved.
@@ -28,13 +27,17 @@
2827
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2928
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3029
*/
31-
public class DataTypeByteArray extends DataType implements Serializable{
30+
public class DataTypeByteArray extends DataType {
3231
byte[] sample;
3332

3433
public DataTypeByteArray(long timestamp, byte[] sample) {
3534
super(timestamp);
3635
this.sample=sample;
3736
}
37+
38+
public DataTypeByteArray() {
39+
}
40+
3841
public byte[] getSample(){
3942
return sample;
4043
}

0 commit comments

Comments
 (0)