Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17088


Ignore:
Timestamp:
07/05/19 15:15:48 (5 years ago)
Author:
abeham
Message:

#2520: tested and simplified check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Clients.Hive/3.3/Util/PersistenceUtil.cs

    r17087 r17088  
    2323using System.Collections.Generic;
    2424using System.IO;
    25 using System.IO.Compression;
    26 using Google.Protobuf;
    2725using HEAL.Attic;
    2826using HeuristicLab.Persistence.Default.Xml;
     
    4745        return (T)ser.Deserialize(sjob);
    4846      } catch (PersistenceException e) {
    49         // Exceptions may arise because data in Hive was uploaded with former XML-based
    50         // persistence or with Attic prior to 1.2.
    5147        if (e.InnerException is InvalidDataException) {
    52           // We assume the data was serialized with HEAL.Attic < 1.2 which did not use
    53           // DeflateStream, but as of 1.2 uses DeflateStream by default
    54           var compressedData = Compress(sjob);
    55           try {
    56             // retry with the job's data compressed
    57             return (T)ser.Deserialize(compressedData);
    58           } catch (PersistenceException e2) {
    59             if (e2.InnerException is InvalidProtocolBufferException
    60               || e2.InnerException is InvalidDataException) {
    61               // retry deserialize original bytes with old persistence
    62               return DeserializeWithXmlParser<T>(sjob);
    63             } else throw;
    64           }
    65         }
    66         if (e.InnerException is InvalidProtocolBufferException) {
    6748          // We assume the data was not serialized with HEAL.Attic, but with the former
    6849          // XML-based persistence
    6950          return DeserializeWithXmlParser<T>(sjob);
    7051        } 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();
    8052      }
    8153    }
Note: See TracChangeset for help on using the changeset viewer.