private boolean addObject(Rebuilder rebuilder, ILowlevelStorage llstore, DODeserializer deser, String pid) { InputStream in = null; try { in = llstore.retrieveObject(pid); DigitalObject obj = new BasicDigitalObject(); deser.deserialize(in, obj, "UTF-8", DOTranslationUtility.SERIALIZE_STORAGE_INTERNAL); rebuilder.addObject(obj); return true; } catch (Exception e) { System.out.println("WARNING: Skipped " + pid + " due to exception: "); e.printStackTrace(); return false; } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } }
/** * {@inheritDoc} */ public void deserialize(InputStream in, DigitalObject obj, String format, String encoding, int transContext) throws ObjectIntegrityException, StreamIOException, UnsupportedTranslationException, ServerException { try { logger.debug("Grabbing deserializer for: {}", format); DODeserializer des = m_deserializers.get(format); if (des == null) { throw new UnsupportedTranslationException("No deserializer exists for format: " + format); } DODeserializer newDes = des.getInstance(); newDes.deserialize(in, obj, encoding, transContext); } catch (UnsupportedEncodingException uee) { throw new UnsupportedTranslationException("Deserializer for format: " + format + " does not support encoding: " + encoding); } }
private boolean addObject(Rebuilder rebuilder, ILowlevelStorage llstore, DODeserializer deser, String pid) { InputStream in = null; try { in = llstore.retrieveObject(pid); DigitalObject obj = new BasicDigitalObject(); deser.deserialize(in, obj, "UTF-8", DOTranslationUtility.SERIALIZE_STORAGE_INTERNAL); rebuilder.addObject(obj); return true; } catch (Exception e) { System.out.println("WARNING: Skipped " + pid + " due to exception: "); e.printStackTrace(); return false; } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } }
/** * {@inheritDoc} */ public void deserialize(InputStream in, DigitalObject obj, String format, String encoding, int transContext) throws ObjectIntegrityException, StreamIOException, UnsupportedTranslationException, ServerException { try { logger.debug("Grabbing deserializer for: {}", format); DODeserializer des = m_deserializers.get(format); if (des == null) { throw new UnsupportedTranslationException("No deserializer exists for format: " + format); } DODeserializer newDes = des.getInstance(); newDes.deserialize(in, obj, encoding, transContext); } catch (UnsupportedEncodingException uee) { throw new UnsupportedTranslationException("Deserializer for format: " + format + " does not support encoding: " + encoding); } }
@Override public DigitalObject call() throws Exception { DigitalObject obj = new BasicDigitalObject(); m_deser.deserialize(m_src, obj, "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE); return obj; } }
private boolean convert(InputStream source, OutputStream destination) { DigitalObject obj = new BasicDigitalObject(); try { m_deserializer.deserialize(source, obj, ENCODING, DOTranslationUtility.AS_IS); setObjectDefaults(obj); if (m_pretty) { prettyPrint(obj, destination); } else { m_serializer.serialize(obj, destination, ENCODING, DOTranslationUtility.AS_IS); } } catch (Exception e) { e.printStackTrace(); return false; } return true; }
private boolean convert(InputStream source, OutputStream destination) { DigitalObject obj = new BasicDigitalObject(); try { m_deserializer.deserialize(source, obj, ENCODING, DOTranslationUtility.AS_IS); setObjectDefaults(obj); if (m_pretty) { prettyPrint(obj, destination); } else { m_serializer.serialize(obj, destination, ENCODING, DOTranslationUtility.AS_IS); } } catch (Exception e) { e.printStackTrace(); return false; } return true; }
protected DigitalObject doDeserialize(InputStream in) throws ObjectIntegrityException, StreamIOException { BasicDigitalObject obj = new BasicDigitalObject(); try { m_deserializer.deserialize(in, obj, "UTF-8", DESERIALIZE_INSTANCE); } catch (UnsupportedEncodingException wontHappen) { fail("Deserializer doesn't support UTF-8?!"); } return obj; }
private DigitalObject[] getDemoObjects() throws Exception { String[] demoSources = {"atom/local-server-demos/simple-image-demo/sdep_demo_2.xml", "atom/local-server-demos/formatting-objects-demo/obj_demo_26.xml"}; DigitalObject[] objects = new DigitalObject[demoSources.length]; int i = 0; for (String source : demoSources) { File sourceFile = new File(DEMO_DIR_PREFIX + source); InputStream in = new FileInputStream(sourceFile); DigitalObject candidate = new BasicDigitalObject(); m_deserializer.deserialize(in, candidate, "utf-8", DOTranslationUtility.DESERIALIZE_INSTANCE); assertNotNull(candidate); objects[i++] = candidate; } return objects; }
private InputStream getTranslatedTestStream(String src, DODeserializer deser, DOSerializer ser) throws Exception { InputStream in = this.getClass().getClassLoader().getResourceAsStream(src); DigitalObject obj = new BasicDigitalObject(); deser.deserialize(in, obj, "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE); ReadableByteArrayOutputStream out = new ReadableByteArrayOutputStream(); ser.serialize(obj, out, "UTF-8", DOTranslationUtility.SERIALIZE_EXPORT_ARCHIVE); return out.toInputStream(); } // Supports legacy test runners
/** * Copies of an object by deserializing and re-serializing. In theory, there * should be no difference between copy generations.. * * @param original * Object to copy * @return Copy formed by serializing and de-serializing the original. * @throws UnsupportedEncodingException * @throws ObjectIntegrityException * @throws StreamIOException */ private DigitalObject translatedCopy(DigitalObject original) throws UnsupportedEncodingException, ObjectIntegrityException, StreamIOException { DigitalObject copy = new BasicDigitalObject(); ByteArrayOutputStream out = new ByteArrayOutputStream(); m_serializer.serialize(original, out, "UTF-8", SERIALIZE_STORAGE_INTERNAL); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); m_deserializer.deserialize(in, copy, "UTF-8", SERIALIZE_STORAGE_INTERNAL); return copy; }
@Test public void testDeserializeWithoutAutoChecksum() throws Exception { Datastream.defaultChecksumType = Datastream.CHECKSUMTYPE_DISABLED; Datastream.autoChecksum = false; BasicDigitalObject obj=new BasicDigitalObject(); obj.setNew(true); m_deserializer.deserialize(this.getClass().getClassLoader().getResourceAsStream("ecm/dataobject1.xml"), obj, "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE); for (Iterator<String> streams=obj.datastreamIdIterator();streams.hasNext();){ String id=streams.next(); for (Datastream version:obj.datastreams(id)){ assertEquals(version.DatastreamID, Datastream.CHECKSUMTYPE_DISABLED, version.DSChecksumType); assertEquals(version.DatastreamID, Datastream.CHECKSUM_NONE, version.DSChecksum); } } } @Test
@Test public void testDeserializeWithoutAutoChecksum() throws Exception { Datastream.defaultChecksumType = Datastream.CHECKSUMTYPE_DISABLED; Datastream.autoChecksum = false; BasicDigitalObject obj=new BasicDigitalObject(); obj.setNew(true); m_deserializer.deserialize(this.getClass().getClassLoader().getResourceAsStream("ecm/dataobject1.xml"), obj, "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE); for (Iterator<String> streams=obj.datastreamIdIterator();streams.hasNext();){ String id=streams.next(); for (Datastream version:obj.datastreams(id)){ assertEquals(version.DatastreamID, Datastream.CHECKSUMTYPE_DISABLED, version.DSChecksumType); assertEquals(version.DatastreamID, Datastream.CHECKSUM_NONE, version.DSChecksum); } } } // Supports legacy test runners
@Test public void testDeserializeWithAutoChecksum() throws Exception { Datastream.defaultChecksumType = "MD5"; Datastream.autoChecksum = true; BasicDigitalObject obj=new BasicDigitalObject(); obj.setNew(true); m_deserializer.deserialize(this.getClass().getClassLoader().getResourceAsStream("ecm/dataobject1.xml"), obj, "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE); for (Iterator<String> streams=obj.datastreamIdIterator();streams.hasNext();){ String id=streams.next(); for (Datastream version:obj.datastreams(id)){ assertEquals(Datastream.getDefaultChecksumType(), version.DSChecksumType); assertEquals(32, version.getChecksum().length()); } } }
@Test public void testDeserializeWithAutoChecksum() throws Exception { Datastream.defaultChecksumType = "MD5"; Datastream.autoChecksum = true; BasicDigitalObject obj=new BasicDigitalObject(); obj.setNew(true); m_deserializer.deserialize(this.getClass().getClassLoader().getResourceAsStream("ecm/dataobject1.xml"), obj, "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE); for (Iterator<String> streams=obj.datastreamIdIterator();streams.hasNext();){ String id=streams.next(); for (Datastream version:obj.datastreams(id)){ assertEquals(Datastream.getDefaultChecksumType(), version.DSChecksumType); assertEquals(32, version.getChecksum().length()); } } }
m_deserializer.deserialize(in, candidate, "utf-8", DOTranslationUtility.DESERIALIZE_INSTANCE); List<AuditRecord> a1 = original.getAuditRecords(); List<AuditRecord> a2 = candidate.getAuditRecords();
@Test public void testSerializeFromFOXML() throws Exception { String source = "src/main/resources/demo/demo-objects/foxml/local-server-demos/image-collection-demo/dataObjects/demo_SmileyBeerGlass.xml"; source = "src/main/resources/demo/demo-objects/foxml/local-server-demos/formatting-objects-demo/obj_demo_26.xml"; InputStream in = new FileInputStream(source); File f = File.createTempFile("test", null); OutputStream out = new FileOutputStream(f); DODeserializer deser = new FOXML1_1DODeserializer(); DigitalObject obj = new BasicDigitalObject(); deser.deserialize(in, obj, "UTF-8", DESERIALIZE_INSTANCE); // some sanity checks setObjectDefaults(obj); DOSerializer serializer = new AtomDOSerializer(); serializer.serialize(obj, out, "UTF-8", SERIALIZE_EXPORT_ARCHIVE); }
m_deserializer.deserialize(in, candidate, "utf-8",