All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.sdk.service.csn2jpa.csn.parser.CsnParser Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
/*******************************************************************************
 * * © 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