Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nicola Amadio
freud-java-serialization
Commits
e2e5a833
Commit
e2e5a833
authored
Jan 04, 2021
by
Nicola Amadio
Browse files
add feature (just one). Seems to serialize corrently but some issues in freud-statistics
parent
941c0528
Changes
6
Hide whitespace changes
Inline
Side-by-side
my-symbols/_nicola_test/idcm__nicola_test_12493.bin
View file @
e2e5a833
No preview for this file type
src/main/java/FreudFeature.java
0 → 100644
View file @
e2e5a833
public
class
FreudFeature
{
private
long
nameOffset
;
// must be same as
private
long
typeOffset
;
private
long
value
;
public
FreudFeature
(
long
value
)
{
this
.
typeOffset
=
0
;
// system feature
this
.
value
=
value
;
}
public
void
setNameOffset
(
long
nameOffset
)
{
this
.
nameOffset
=
nameOffset
;
}
public
long
getTypeOffset
()
{
return
typeOffset
;
}
public
long
getValue
()
{
return
value
;
}
}
src/main/java/FreudFeatureName.java
0 → 100644
View file @
e2e5a833
public
class
FreudFeatureName
{
private
short
VarNameLen
;
private
String
VarName
;
public
FreudFeatureName
(
short
varNameLen
,
String
varName
)
{
VarNameLen
=
varNameLen
;
VarName
=
varName
;
}
public
short
getVarNameLen
()
{
return
VarNameLen
;
}
public
String
getVarName
()
{
return
VarName
;
}
}
src/main/java/Main.java
View file @
e2e5a833
import
com.google.common.primitives.Ints
;
import
com.google.common.primitives.Shorts
;
import
org.apache.commons.lang.ArrayUtils
;
import
java.io.*
;
import
java.nio.ByteBuffer
;
import
java.util.List
;
import
java.nio.channels.SeekableByteChannel
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.LinkedList
;
public
class
Main
{
...
...
@@ -27,32 +33,54 @@ public class Main {
private
static
void
writeObjectToFile
(
FileOutputStream
fos
,
TestClassToSerialize
myObject
)
throws
IOException
{
fos
.
write
(
intToByteArray
(
myObject
.
getSymbolNameLen
()));
fos
.
write
(
myObject
.
getSymbolName
().
getBytes
());
Path
path
=
Paths
.
get
(
PATHNAME
);
LinkedList
<
Long
>
featureOffsets
=
new
LinkedList
<>();
fos
.
write
(
intToByteArray
(
myObject
.
getFeatureNamesCount
()));
for
(
FreudFeatureName
featureName:
myObject
.
getFeatureNamesList
())
{
SeekableByteChannel
ch
=
Files
.
newByteChannel
(
path
);
// Defaults to read-only
featureOffsets
.
add
(
ch
.
position
());
fos
.
write
(
shortToByteArray
(
featureName
.
getVarNameLen
()));
fos
.
write
(
featureName
.
getVarName
().
getBytes
());
}
fos
.
write
(
intToByteArray
(
myObject
.
getTypeNamesCount
()));
fos
.
write
(
intToByteArray
(
myObject
.
getSamplesCount
()));
List
<
Sample
>
samples
=
myObject
.
getSampleList
();
for
(
Sample
sample:
samples
)
{
for
(
Sample
sample:
myObject
.
getSampleList
())
{
fos
.
write
(
intToByteArray
(
sample
.
getUidR
()));
fos
.
write
(
longToByte
s
(
sample
.
getTime
()));
fos
.
write
(
longToByte
s
(
sample
.
getMem
()));
fos
.
write
(
longToByte
s
(
sample
.
getLockHoldingTime
()));
fos
.
write
(
longToByte
s
(
sample
.
getWaitingTime
()));
fos
.
write
(
longToByte
s
(
sample
.
getMinorPageFaults
()));
fos
.
write
(
longToByte
s
(
sample
.
getMajorPageFaults
()));
fos
.
write
(
longToByte
Array
(
sample
.
getTime
()));
fos
.
write
(
longToByte
Array
(
sample
.
getMem
()));
fos
.
write
(
longToByte
Array
(
sample
.
getLockHoldingTime
()));
fos
.
write
(
longToByte
Array
(
sample
.
getWaitingTime
()));
fos
.
write
(
longToByte
Array
(
sample
.
getMinorPageFaults
()));
fos
.
write
(
longToByte
Array
(
sample
.
getMajorPageFaults
()));
fos
.
write
(
intToByteArray
(
sample
.
getNumOfFeatures
()));
int
i
=
0
;
for
(
FreudFeature
feature:
sample
.
getFeatures
())
{
fos
.
write
(
longToByteArray
(
20
));
fos
.
write
(
longToByteArray
(
feature
.
getTypeOffset
()));
fos
.
write
(
longToByteArray
(
feature
.
getValue
()));
i
++;
}
fos
.
write
(
intToByteArray
(
sample
.
getNumOfBranches
()));
fos
.
write
(
intToByteArray
(
sample
.
getNumOfChildren
()));
}
fos
.
close
();
}
public
static
byte
[]
intToByteArray
(
int
data
)
{
byte
[]
bytes
=
Ints
.
toByteArray
(
data
);
public
static
byte
[]
shortToByteArray
(
short
x
)
{
byte
[]
bytes
=
Shorts
.
toByteArray
(
x
);
ArrayUtils
.
reverse
(
bytes
);
return
bytes
;
}
public
static
byte
[]
intToByteArray
(
int
x
)
{
byte
[]
bytes
=
Ints
.
toByteArray
(
x
);
ArrayUtils
.
reverse
(
bytes
);
return
bytes
;
}
public
static
byte
[]
longToByte
s
(
long
x
)
{
public
static
byte
[]
longToByte
Array
(
long
x
)
{
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
Long
.
BYTES
);
buffer
.
putLong
(
x
);
byte
[]
array
=
buffer
.
array
();
...
...
src/main/java/Sample.java
View file @
e2e5a833
import
java.util.LinkedList
;
import
java.util.List
;
public
class
Sample
{
int
uidR
;
long
time
;
// so far, this is the only sample variable to be set to a value, the others get set to 0
long
mem
;
long
lockHoldingTime
;
long
waitingTime
;
long
minorPageFaults
;
long
majorPageFaults
;
int
numOfFeatures
;
int
numOfBranches
;
int
numOfChildren
;
private
int
uidR
;
private
long
time
;
// so far, this is the only sample variable to be set to a value, the others get set to 0
private
long
mem
;
private
long
lockHoldingTime
;
private
long
waitingTime
;
private
long
minorPageFaults
;
private
long
majorPageFaults
;
private
int
numOfFeatures
;
private
int
numOfBranches
;
private
int
numOfChildren
;
private
List
<
FreudFeature
>
features
;
public
Sample
(
long
time
)
{
this
.
time
=
time
;
...
...
@@ -18,10 +22,12 @@ public class Sample {
waitingTime
=
0
;
minorPageFaults
=
0
;
majorPageFaults
=
0
;
numOfFeatures
=
0
;
numOfFeatures
=
1
;
numOfBranches
=
0
;
numOfChildren
=
0
;
features
=
new
LinkedList
<>();
long
value
=
10
;
// random value
features
.
add
(
new
FreudFeature
(
value
));
}
public
int
getUidR
()
{
...
...
@@ -56,6 +62,10 @@ public class Sample {
return
numOfFeatures
;
}
public
List
<
FreudFeature
>
getFeatures
()
{
return
features
;
}
public
int
getNumOfBranches
()
{
return
numOfBranches
;
}
...
...
src/main/java/TestClassToSerialize.java
View file @
e2e5a833
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
TestClassToSerialize
implements
Serializable
{
...
...
@@ -8,6 +9,7 @@ public class TestClassToSerialize implements Serializable {
private
String
symbolName
;
// FEATURE NAMES
private
int
featureNamesCount
;
List
<
FreudFeatureName
>
featureNames
;
// TYPE NAMES
int
typeNamesCount
;
// SAMPLES
...
...
@@ -18,7 +20,13 @@ public class TestClassToSerialize implements Serializable {
public
TestClassToSerialize
(
String
symbolName
,
int
samplesCount
)
{
this
.
symbolNameLen
=
symbolName
.
length
();
this
.
symbolName
=
symbolName
;
this
.
featureNamesCount
=
0
;
// feature names
this
.
featureNamesCount
=
1
;
String
myVar
=
"my var"
;
featureNames
=
new
LinkedList
<>();
featureNames
.
add
(
new
FreudFeatureName
((
short
)
myVar
.
length
(),
myVar
));
this
.
typeNamesCount
=
0
;
this
.
samplesCount
=
samplesCount
;
this
.
sampleList
=
new
ArrayList
<>();
...
...
@@ -55,6 +63,10 @@ public class TestClassToSerialize implements Serializable {
this
.
featureNamesCount
=
featureNamesCount
;
}
public
List
<
FreudFeatureName
>
getFeatureNamesList
()
{
return
featureNames
;
}
// TYPE NAMES
public
int
getTypeNamesCount
()
{
return
typeNamesCount
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment