Пример #1
0
  @NotNull
  @Override
  public SModel load(@NotNull DataSource dataSource, @NotNull Map<String, String> options)
      throws IOException {
    if (!(dataSource instanceof StreamDataSource)) {
      throw new UnsupportedDataSourceException(dataSource);
    }

    StreamDataSource source = (StreamDataSource) dataSource;
    SModelHeader binaryModelHeader;
    try {
      binaryModelHeader = BinaryPersistence.readHeader(source);
    } catch (ModelReadException e) {
      if (e.getCause() instanceof IOException) {
        throw (IOException) e.getCause();
      }
      throw new IOException(e.getMessageEx(), e);
    }
    if (Boolean.parseBoolean(options.get(MetaModelInfoProvider.OPTION_KEEP_READ_METAINFO))) {
      binaryModelHeader.setMetaInfoProvider(
          new StuffedMetaModelInfo(
              new RegularMetaModelInfo(binaryModelHeader.getModelReference())));
    }
    return new DefaultSModelDescriptor(new PersistenceFacility(this, source), binaryModelHeader);
  }
Пример #2
0
 public static Map<String, String> getDigestMap(@NotNull StreamDataSource source) {
   try {
     SModelHeader binaryModelHeader = BinaryPersistence.readHeader(source);
     binaryModelHeader.setMetaInfoProvider(
         new StuffedMetaModelInfo(
             new RegularMetaModelInfo(binaryModelHeader.getModelReference())));
     final ModelLoadResult loadedModel =
         BinaryPersistence.readModel(binaryModelHeader, source, false);
     Map<String, String> result =
         BinaryPersistence.getDigestMap(
             loadedModel.getModel(), binaryModelHeader.getMetaInfoProvider());
     result.put(GeneratableSModel.FILE, ModelDigestUtil.hashBytes(source.openInputStream()));
     return result;
   } catch (ModelReadException ignored) {
     /* ignore */
   } catch (IOException e) {
     /* ignore */
   }
   return null;
 }