summaryrefslogtreecommitdiffstats
path: root/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/impl/SerializableTypeConverter.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/impl/SerializableTypeConverter.java')
-rw-r--r--sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/impl/SerializableTypeConverter.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/impl/SerializableTypeConverter.java b/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/impl/SerializableTypeConverter.java
new file mode 100644
index 0000000000..affa199b04
--- /dev/null
+++ b/sandbox/kgoodson/mappingFramework/sdo-snapshot/src/main/java/com/agfa/hap/sdo/impl/SerializableTypeConverter.java
@@ -0,0 +1,61 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.agfa.hap.sdo.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+public class SerializableTypeConverter extends TypeConverter<Serializable> {
+
+ @Override
+ public Serializable parse(String str) {
+ byte[] bytes = bytesTypeConverter.parse(str);
+ ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+ try {
+ ObjectInput in = new ObjectInputStream(bis);
+ return (Serializable) in.readObject();
+ } catch(IOException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException cnfe) {
+ throw new RuntimeException(cnfe);
+ }
+ }
+
+ @Override
+ public String toString(Serializable instance) {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ ObjectOutput out = new ObjectOutputStream(bos);
+ out.writeObject(instance);
+ out.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return bytesTypeConverter.toString(bos.toByteArray());
+ }
+
+ private BytesTypeConverter bytesTypeConverter = new BytesTypeConverter();
+}