X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloader.java;h=70a193ae716d912bcaba771585105fe62bcbf0ef;hp=9bc14a8a5254bbd6be9019e52dca4963146539fb;hb=9cb50c365e3bf7a74ffa40a45630a0e7be40b526;hpb=b767ceb6adea75829f9eeb417d2a3f3e3f445ba9 diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 9bc14a8..70a193a 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -37,16 +37,13 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.logging.Logging; +import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.service.AbstractService; import net.pterodactylus.util.xml.SimpleXML; import net.pterodactylus.util.xml.XML; import org.w3c.dom.Document; -import com.google.common.base.Optional; -import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; - import freenet.client.FetchResult; import freenet.keys.FreenetURI; import freenet.support.api.Bucket; @@ -253,7 +250,7 @@ public class SoneDownloader extends AbstractService { Integer protocolVersion = null; String soneProtocolVersion = soneXml.getValue("protocol-version", null); if (soneProtocolVersion != null) { - protocolVersion = Optional.fromNullable(Ints.tryParse(soneProtocolVersion)).or(0); + protocolVersion = Numbers.safeParseInteger(soneProtocolVersion); } if (protocolVersion == null) { logger.log(Level.INFO, "No protocol version found, assuming 0."); @@ -330,9 +327,9 @@ public class SoneDownloader extends AbstractService { String profileFirstName = profileXml.getValue("first-name", null); String profileMiddleName = profileXml.getValue("middle-name", null); String profileLastName = profileXml.getValue("last-name", null); - Integer profileBirthDay = Ints.tryParse(profileXml.getValue("birth-day", null)); - Integer profileBirthMonth = Ints.tryParse(profileXml.getValue("birth-month", null)); - Integer profileBirthYear = Ints.tryParse(profileXml.getValue("birth-year", null)); + Integer profileBirthDay = Numbers.safeParseInteger(profileXml.getValue("birth-day", null)); + Integer profileBirthMonth = Numbers.safeParseInteger(profileXml.getValue("birth-month", null)); + Integer profileBirthYear = Numbers.safeParseInteger(profileXml.getValue("birth-year", null)); Profile profile = new Profile(sone).setFirstName(profileFirstName).setMiddleName(profileMiddleName).setLastName(profileLastName); profile.setBirthDay(profileBirthDay).setBirthMonth(profileBirthMonth).setBirthYear(profileBirthYear); /* avatar is processed after images are loaded. */ @@ -483,9 +480,9 @@ public class SoneDownloader extends AbstractService { logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid images!", sone)); return null; } - long creationTime = Optional.fromNullable(Longs.tryParse(imageCreationTimeString)).or(0L); - int imageWidth = Optional.fromNullable(Ints.tryParse(imageWidthString)).or(0); - int imageHeight = Optional.fromNullable(Ints.tryParse(imageHeightString)).or(0); + long creationTime = Numbers.safeParseLong(imageCreationTimeString, 0L); + int imageWidth = Numbers.safeParseInteger(imageWidthString, 0); + int imageHeight = Numbers.safeParseInteger(imageHeightString, 0); if ((imageWidth < 1) || (imageHeight < 1)) { logger.log(Level.WARNING, String.format("Downloaded Sone %s contains image %s with invalid dimensions (%s, %s)!", sone, imageId, imageWidthString, imageHeightString)); return null;