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

com.axibase.tsd.driver.jdbc.protocol.MetadataRetriever Maven / Gradle / Ivy

There is a newer version: 1.4.11
Show newest version
package com.axibase.tsd.driver.jdbc.protocol;

import java.io.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.axibase.tsd.driver.jdbc.content.ContentDescription;
import com.axibase.tsd.driver.jdbc.logging.LoggingFacade;
import org.apache.calcite.avatica.org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.ArrayUtils;

import static com.axibase.tsd.driver.jdbc.DriverConstants.DEFAULT_CHARSET;

public class MetadataRetriever {
	private static final LoggingFacade logger = LoggingFacade.getLogger(MetadataRetriever.class);

	private static final String SCHEME_HEADER = "Link";
	private static final String START_LINK = "> map, ContentDescription contentDescription) {
		printHeaders(map);
		List list = map.get(SCHEME_HEADER);
		String value = list != null && !list.isEmpty() ? list.get(0) : null;
		if (value != null && value.startsWith(START_LINK) && value.endsWith(END_LINK)) {
			final String encoded = value.substring(START_LINK.length(), value.length() - END_LINK.length());
			String json = new String(Base64.decodeBase64(encoded), DEFAULT_CHARSET);
			if (logger.isTraceEnabled()) {
				logger.trace("JSON schema: " + json);
			}
			contentDescription.setJsonScheme(json);
		}
	}

	private static void printHeaders(Map> map) {
		if (logger.isTraceEnabled()) {
			for (Map.Entry> entry : map.entrySet()) {
				logger.trace("Key: {} Value: {} ", entry.getKey(), entry.getValue());
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy