ru.r2cloud.apt.model.ControlFile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apt-man Show documentation
Show all versions of apt-man Show documentation
Library for managing APT repository
The newest version!
package ru.r2cloud.apt.model;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ControlFile {
private static final Logger LOG = LoggerFactory.getLogger(ControlFile.class);
private String packageName;
private String version;
private Architecture arch;
private String contents;
private String filename;
private long size;
private final Map payload = new HashMap<>();
public Map getPayload() {
return payload;
}
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Architecture getArch() {
return arch;
}
public void setArch(Architecture arch) {
this.arch = arch;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getFilename() {
return filename;
}
public void load(String str) {
contents = str.trim();
if (contents.charAt(contents.length() - 1) != '\n') {
contents += "\n";
}
String[] lines = str.split("\\r?\\n");
for (String cur : lines) {
String[] parts = cur.split(":");
if (parts.length != 2) {
continue;
}
String value = parts[1].trim();
if (parts[0].equalsIgnoreCase("Package")) {
setPackageName(value);
continue;
}
if (parts[0].equalsIgnoreCase("Version")) {
setVersion(value);
continue;
}
if (parts[0].equalsIgnoreCase("Architecture")) {
setArch(Architecture.valueOf(value.toUpperCase(Locale.UK)));
continue;
}
if (parts[0].equalsIgnoreCase("Filename")) {
setFilename(value);
continue;
}
if (parts[0].equalsIgnoreCase("Size")) {
try {
setSize(Long.valueOf(value));
} catch (Exception e) {
LOG.error("invalid size value: " + value, e);
}
}
}
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public void append(String str) {
contents += str + "\n";
}
}