public abstract class IO extends Object
// Creating result population.
EvolutionResult<DoubleGene, Double> result = stream
.collect(toBestEvolutionResult());
// Writing the population to disk.
final File file = new File("population.xml");
IO.jaxb.write(result.getPopulation(), file);
// Reading the population from disk.
Population<DoubleGene, Double> population =
(Population<DoubleGene, Double>)IO.jaxb.read(file);
EvolutionStream<DoubleGene, Double> stream = Engine
.build(ff, gtf)
.stream(population, 1);
jaxb
marshalling also allows to read and write own classes. For
this you have to register your @XmlType
d class first.
// The user defined 'JAXB' model class.
@XmlRootElement(name = "data-class")
@XmlType(name = "DataClass")
@XmlAccessorType(XmlAccessType.FIELD)
public static final class DataClass {
@XmlAttribute public String name;
@XmlValue public String value;
}
// Register the 'JAXB' model class.
IO.JAXB.register(DataClass.class);
final DataClass data = ...;
IO.jaxb.write(data, "data.xml");
IO.JAXB.register(DataClass.class)
more than once.Modifier and Type | Class and Description |
---|---|
static class |
IO.JAXB
Deprecated.
Since the
javax.xml.bind is marked as deprecated for
removal in Java 9, the JAXB marshalling will be removed as
well. Use the org.jenetics.xml module when writing
and reading Jenetics data-objects as XML. |
Modifier and Type | Field and Description |
---|---|
static IO |
jaxb
Deprecated.
Since the
javax.xml.bind is marked as deprecated for
removal in Java 9, the JAXB marshalling will be removed as
well. Use the org.jenetics.xml module when writing
and reading Jenetics data-objects as XML. |
static IO |
object
IO implementation for "native" Java serialization.
|
Modifier | Constructor and Description |
---|---|
protected |
IO() |
Modifier and Type | Method and Description |
---|---|
<T> T |
read(Class<T> type,
File file)
Reads an object from the given file.
|
abstract <T> T |
read(Class<T> type,
InputStream in)
Reads an object from the given input stream.
|
<T> T |
read(Class<T> type,
Path path)
Reads an object from the given file.
|
<T> T |
read(Class<T> type,
String path)
Reads an object from the given file.
|
Object |
read(File file)
Reads an object from the given file.
|
Object |
read(InputStream in)
Reads an object from the given input stream.
|
Object |
read(Path path)
Reads an object from the given file.
|
Object |
read(String path)
Reads an object from the given file.
|
void |
write(Object object,
File file)
Write the (serializable) object to the given file.
|
abstract void |
write(Object object,
OutputStream out)
Write the (serializable) object to the given output stream.
|
void |
write(Object object,
Path path)
Write the (serializable) object to the given path.
|
void |
write(Object object,
String path)
Write the (serializable) object to the given path.
|
@Deprecated public static final IO jaxb
javax.xml.bind
is marked as deprecated for
removal in Java 9, the JAXB marshalling will be removed as
well. Use the org.jenetics.xml
module when writing
and reading Jenetics data-objects as XML.protected IO()
public void write(Object object, String path) throws IOException
object
- the object to serialize.path
- the path to write the object to.NullPointerException
- if one of the arguments is null
.IOException
- if the object could not be serialized.public void write(Object object, Path path) throws IOException
object
- the object to serialize.path
- the path to write the object to.NullPointerException
- if one of the arguments is null
.IOException
- if the object could not be serialized.public void write(Object object, File file) throws IOException
object
- the object to serialize.file
- the file to write the object to.NullPointerException
- if one of the arguments is null
.IOException
- if the object could not be serialized.public abstract void write(Object object, OutputStream out) throws IOException
object
- the object to serialize.out
- the output stream to write the object to.NullPointerException
- if one of the arguments is null
.IOException
- if the object could not be serialized.public <T> T read(Class<T> type, String path) throws IOException
T
- the type of the read objectpath
- the path to read from.type
- the type of the read object.NullPointerException
- if the input stream in
is null
.IOException
- if the object could not be read.public Object read(String path) throws IOException
path
- the path to read from.NullPointerException
- if the input stream in
is null
.IOException
- if the object could not be read.public <T> T read(Class<T> type, Path path) throws IOException
T
- the type of the read objectpath
- the path to read from.type
- the type of the read object.NullPointerException
- if the input stream in
is null
.IOException
- if the object could not be read.public Object read(Path path) throws IOException
path
- the path to read from.NullPointerException
- if the input stream in
is null
.IOException
- if the object could not be read.public <T> T read(Class<T> type, File file) throws IOException
T
- the type of the read objectfile
- the file to read from.type
- the type of the read object.NullPointerException
- if the input stream in
is null
.IOException
- if the object could not be read.public Object read(File file) throws IOException
file
- the file to read from.NullPointerException
- if the input stream in
is null
.IOException
- if the object could not be read.public abstract <T> T read(Class<T> type, InputStream in) throws IOException
T
- the type of the read objectin
- the input stream to read from.type
- the type of the read object.NullPointerException
- if the input stream in
is null
.IOException
- if the object could not be read.public Object read(InputStream in) throws IOException
in
- the input stream to read from.NullPointerException
- if the input stream in
is null
.IOException
- if the object could not be read.© 2007-2017 Franz Wilhelmstötter (2017-08-22 19:30)