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

io.guixer.maven.ResponseParser Maven / Gradle / Ivy

There is a newer version: 0.0.25
Show newest version
package io.guixer.maven;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

abstract class ResponseParser {

	public static MyUpload toUpload(
		final File jsonFile
	) throws IOException, ParseException {

		final String json = FileUtils.readFileToString(jsonFile, UTF_8);

		return toUpload(json);
	}

	public static MyUpload toUpload(
		final String json
	) throws ParseException {

		final JSONObject o = (JSONObject) new JSONParser().parse(json);

		final String uploadId = (String) o.get("id");

		return new MyUpload() {

			@Override
			public String getId() {

				return uploadId;
			}
		};
	}

	public interface MyUpload {

		String getId();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy