Changeset 17088
- Timestamp:
- 07/05/19 15:15:48 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Clients.Hive/3.3/Util/PersistenceUtil.cs
r17087 r17088 23 23 using System.Collections.Generic; 24 24 using System.IO; 25 using System.IO.Compression;26 using Google.Protobuf;27 25 using HEAL.Attic; 28 26 using HeuristicLab.Persistence.Default.Xml; … … 47 45 return (T)ser.Deserialize(sjob); 48 46 } catch (PersistenceException e) { 49 // Exceptions may arise because data in Hive was uploaded with former XML-based50 // persistence or with Attic prior to 1.2.51 47 if (e.InnerException is InvalidDataException) { 52 // We assume the data was serialized with HEAL.Attic < 1.2 which did not use53 // DeflateStream, but as of 1.2 uses DeflateStream by default54 var compressedData = Compress(sjob);55 try {56 // retry with the job's data compressed57 return (T)ser.Deserialize(compressedData);58 } catch (PersistenceException e2) {59 if (e2.InnerException is InvalidProtocolBufferException60 || e2.InnerException is InvalidDataException) {61 // retry deserialize original bytes with old persistence62 return DeserializeWithXmlParser<T>(sjob);63 } else throw;64 }65 }66 if (e.InnerException is InvalidProtocolBufferException) {67 48 // We assume the data was not serialized with HEAL.Attic, but with the former 68 49 // XML-based persistence 69 50 return DeserializeWithXmlParser<T>(sjob); 70 51 } else throw; 71 }72 }73 74 private static byte[] Compress(byte[] sjob) {75 using (var memStream = new MemoryStream(sjob.Length)) {76 using (var deflateStream = new DeflateStream(memStream, CompressionMode.Compress)) {77 deflateStream.Write(sjob, 0, sjob.Length);78 }79 return memStream.ToArray();80 52 } 81 53 }
Note: See TracChangeset
for help on using the changeset viewer.