try {
stream = RestAPI.getCachingInputStream(new URL(url), true);
Project project = mapper.readValue(stream, Project.class);
build = project.getBuild();
} catch (IOException e) {
throw new RestfulAPIException("Error accessing URL [" + url + "]", e);
} finally {
IOUtils.closeQuietly(stream);
}
// Check to see if stable has newer release
if (channel == Channel.STABLE) {
return String.valueOf(build);
} else {
url = RestAPI.getSpoutcraftURL(Channel.STABLE);
try {
stream = RestAPI.getCachingInputStream(new URL(url), true);
Project stable = mapper.readValue(stream, Project.class);
// Stable release is newer
if (stable.getBuild() > build) {
return String.valueOf(stable.getBuild());
} else {
return String.valueOf(build);
}
} catch (IOException e) {
throw new RestfulAPIException("Error accessing URL [" + url + "]", e);
} finally {
IOUtils.closeQuietly(stream);
}
}
} else {
// Find the newest build for the Minecraft version
String url = RestAPI.ALL_BUILDS_URL;
try {
final String mcVersion = getMinecraft().getVersion();
stream = RestAPI.getCachingInputStream(new URL(url), true);
ChannelData data = mapper.readValue(stream, ChannelData.class);
HashSet<String> builds = new HashSet<String>(100);
for (VersionData v : data.stable) {
if (v.minecraftVersion.equals(mcVersion)) {
builds.add(v.buildNumber);
}
}
for (VersionData v : data.beta) {
if (v.minecraftVersion.equals(mcVersion)) {
builds.add(v.buildNumber);
}
}
for (VersionData v : data.dev) {
if (v.minecraftVersion.equals(mcVersion)) {
builds.add(v.buildNumber);
}
}
ArrayList<String> buildList = new ArrayList<String>(builds);
Collections.sort(buildList);
return buildList.get(buildList.size() - 1);
} catch (IOException e) {
throw new RestfulAPIException("Error accessing URL [" + url + "]", e);
} finally {
IOUtils.closeQuietly(stream);
}
}
}