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

org.gridkit.jvmtool.spi.parsers.JsonEventDumpHelper Maven / Gradle / Ivy

package org.gridkit.jvmtool.spi.parsers;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;

public class JsonEventDumpHelper {

	public static JsonEventSource open(InputStreamSource source, Map options) throws IOException {
		StringBuilder sb = new StringBuilder();
		ServiceLoader factories = ServiceLoader.load(JsonEventDumpParserFactory.class);
		Iterator it = factories.iterator();
		while(it.hasNext()) {
			try {
				JsonEventDumpParserFactory factory = it.next();
				JsonEventDumpParser parser = factory.createParser(options);
				if (parser != null) {
					try {
						JsonEventSource src = parser.open(source);
						if (src != null) {
							return src;
						}
						sb.append(" " + parser.toString() + " -> unsupported format\n");
					}
					catch(Exception e) {
						String pname = parser.toString();
						sb.append(" " + pname + " -> " + e.getMessage() + "\n");
					}
				}
			}
			catch(Throwable e) {
				// ignore
			}
		}
		// none of parser was
		if (sb.length() == 0) {
			throw new IOException("Unable to open dump, no parsers are available");
		}
		else {
			throw new IOException("Unable to open dump\n" + sb.toString());
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy