com.sap.cloud.sdk.service.csn2jpa.csn.parser.CsnParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of csn-reader Show documentation
Show all versions of csn-reader Show documentation
API for reading CDS models in CSN format
/*******************************************************************************
* * © 2018 SAP SE or an SAP affiliate company. All rights reserved. *
******************************************************************************/
package com.sap.cloud.sdk.service.csn2jpa.csn.parser;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.json.JsonSanitizer;
import com.sap.cloud.sdk.service.csn2jpa.cds.model.CdsModel;
import com.sap.cloud.sdk.service.csn2jpa.csn.parser.reader.ModelReader;
public class CsnParser {
private CsnParser() {
}
public static CdsModel parseData(byte[] data) throws IOException {
return parseStream(new ByteArrayInputStream(data));
}
public static CdsModel parseStream(InputStream is) throws IOException {
try (final Reader reader = new InputStreamReader(is, Charsets.UTF_8)) {
String json = JsonSanitizer.sanitize(CharStreams.toString(reader));
JsonElement jsonElement = new JsonParser().parse(json);
return ModelReader.read(jsonElement.getAsJsonObject());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy