com.github.eliux.mega.cmd.ExportInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of megacmd4j Show documentation
Show all versions of megacmd4j Show documentation
Java client library that works on top of MEGAcmd to provide access to the services of Mega.nz
package com.github.eliux.mega.cmd;
import com.github.eliux.mega.error.MegaInvalidResponseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ExportInfo {
private static final Pattern LIST_PATTERN =
Pattern.compile("(?\\S+) \\(.+link: (?http[s]?://mega.nz/#.+)\\)");
private final String remotePath;
private final String publicLink;
public ExportInfo(String remotePath, String publicLink) {
this.remotePath = remotePath;
this.publicLink = publicLink;
}
public String getRemotePath() {
return remotePath;
}
public String getPublicLink() {
return publicLink;
}
public static ExportInfo parseExportInfo(String exportInfoStr) {
final String[] tokens = exportInfoStr.replace("Exported ", "")
.split(": ");
return new ExportInfo(tokens[0], tokens[1]);
}
public static ExportInfo parseExportListInfo(String exportInfoLine) {
try {
final Matcher matcher = LIST_PATTERN.matcher(exportInfoLine);
if (matcher.find()) {
return new ExportInfo(
matcher.group("remotePath"),
matcher.group("publicLink")
);
}
} catch (IllegalStateException | IndexOutOfBoundsException ex) {
//Don't let it go outside
}
throw new MegaInvalidResponseException(exportInfoLine);
}
}