]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/examples/org/simantics/databoard/example/old/SerializerExample1.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / examples / org / simantics / databoard / example / old / SerializerExample1.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  Industry THTH ry.
4  *  All rights reserved. This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License v1.0
6  *  which accompanies this distribution, and is available at
7  *  http://www.eclipse.org/legal/epl-v10.html
8  *
9  *  Contributors:
10  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.example.old;
13
14 import java.awt.geom.Rectangle2D;
15 import java.io.IOException;
16 import java.util.Arrays;
17
18 import org.simantics.databoard.Bindings;
19 import org.simantics.databoard.binding.Binding;
20 import org.simantics.databoard.binding.error.BindingException;
21 import org.simantics.databoard.serialization.SerializationException;
22 import org.simantics.databoard.serialization.Serializer;
23
24 /**
25  * The example demonstrates how to create and use serializer. 
26  *
27  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
28  */
29 public class SerializerExample1 {
30                 
31         public static void main(String[] args) throws IOException, SerializationException, BindingException
32         {
33                 // Initializer rectangle, binding and serializer 
34                 Rectangle2D rect = new Rectangle2D.Double(5, 5, 100, 200);
35                 Binding rectangleBinding = Bindings.getBindingUnchecked(Rectangle2D.Double.class);
36                 Serializer rectangleSerializer = Bindings.getSerializerUnchecked( rectangleBinding );
37
38                 // Serializer
39                 byte data[] = rectangleSerializer.serialize( rect );
40                 System.out.println(Arrays.toString( data ));
41                 
42                 // Deserialize
43                 Rectangle2D rect2 = (Rectangle2D) rectangleSerializer.deserialize(data);
44                 System.out.println( Bindings.toString(rect2) );         
45         }
46         
47
48 }
49