use of net.runelite.http.service.util.exception.InternalServerErrorException in project runelite by runelite.
the class XteaService method checkKeys.
private boolean checkKeys(CacheEntry cache, int regionId, int[] keys) {
int x = regionId >>> 8;
int y = regionId & 0xFF;
String archiveName = new StringBuilder().append('l').append(x).append('_').append(y).toString();
int archiveNameHash = Djb2.hash(archiveName);
ArchiveEntry archiveEntry = cacheService.findArchiveForTypeAndName(cache, IndexType.MAPS, archiveNameHash);
if (archiveEntry == null) {
throw new InternalServerErrorException("Unable to find archive for region");
}
byte[] data = cacheService.getArchive(archiveEntry);
if (data == null) {
throw new InternalServerErrorException("Unable to get archive data");
}
try {
Container.decompress(data, keys);
return true;
} catch (IOException ex) {
return false;
}
}
use of net.runelite.http.service.util.exception.InternalServerErrorException in project runelite by runelite.
the class BlogService method getBlogPosts.
public List<FeedItem> getBlogPosts() throws IOException {
Request request = new Request.Builder().url(RSS_URL).build();
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Error getting blog posts: " + response.message());
}
try {
InputStream in = response.body().byteStream();
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
Element documentElement = document.getDocumentElement();
NodeList documentItems = documentElement.getElementsByTagName("entry");
List<FeedItem> items = new ArrayList<>();
for (int i = 0; i < Math.min(documentItems.getLength(), 3); i++) {
Node item = documentItems.item(i);
NodeList children = item.getChildNodes();
String title = null;
String summary = null;
String link = null;
long timestamp = -1;
for (int j = 0; j < children.getLength(); j++) {
Node childItem = children.item(j);
String nodeName = childItem.getNodeName();
switch(nodeName) {
case "title":
title = childItem.getTextContent();
break;
case "summary":
summary = childItem.getTextContent().replace("\n", "").trim();
break;
case "link":
link = childItem.getAttributes().getNamedItem("href").getTextContent();
break;
case "updated":
timestamp = DATE_FORMAT.parse(childItem.getTextContent()).getTime();
break;
}
}
if (title == null || summary == null || link == null || timestamp == -1) {
throw new InternalServerErrorException("Failed to find title, summary, link and/or timestamp in the blog post feed");
}
items.add(new FeedItem(FeedItemType.BLOG_POST, title, summary, link, timestamp));
}
return items;
} catch (ParserConfigurationException | SAXException | ParseException e) {
throw new InternalServerErrorException("Failed to parse blog posts: " + e.getMessage());
}
}
}
Aggregations