package de.thedevstack.conversationsplus.entities; import de.thedevstack.conversationsplus.enums.FileStatus; import eu.siacs.conversations.utils.MimeUtils; /** * */ public class FileParams { private String name; private String originalFilename; private String path; private String url; private String mimeType; private long size = 0; private int width = 0; private int height = 0; private FileStatus fileStatus; private byte[] aeskey; private byte[] iv; public FileParams() { fileStatus = FileStatus.UNDEFINED; } public FileParams(String url) { this(); this.url = url; } public FileParams(String url, long size) { this(url); this.size = size; } public FileParams(String url, long size, int width, int height) { this(url, size); this.width = width; this.height = height; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public long getSize() { return size; } public void setSize(long size) { this.size = size; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public String getMimeType() { return mimeType; } public void setMimeType(String mimeType) { this.mimeType = mimeType; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPath() { return path; } public void setKeyAndIv(byte[] keyIvCombo) { if (keyIvCombo.length == 48) { this.aeskey = new byte[32]; this.iv = new byte[16]; System.arraycopy(keyIvCombo, 0, this.iv, 0, 16); System.arraycopy(keyIvCombo, 16, this.aeskey, 0, 32); } else if (keyIvCombo.length >= 32) { this.aeskey = new byte[32]; System.arraycopy(keyIvCombo, 0, aeskey, 0, 32); } else if (keyIvCombo.length >= 16) { this.aeskey = new byte[16]; System.arraycopy(keyIvCombo, 0, this.aeskey, 0, 16); } } public void setKey(byte[] key) { this.aeskey = key; } public void setIv(byte[] iv) { this.iv = iv; } public byte[] getKey() { return this.aeskey; } public byte[] getIv() { return this.iv; } /** * Sets the path to the file. * If no file name is stored yet here - this method tries to extract the file name from the path. * If the file name is stored here and the path does not end with the name - the name is appended to the path. * @param path the path to be stored */ public void setPath(String path) { if (null != path) { if (null != this.name) { path = (!path.endsWith(this.name)) ? path + "/" + this.name : path; } else { if (!path.endsWith("/")) { this.setName(path.substring(path.lastIndexOf('/') + 1)); } } if (null == this.mimeType) { int start = path.lastIndexOf('.') + 1; if (start < path.length()) { String extension = path.substring(start); this.mimeType = MimeUtils.guessMimeTypeFromExtension(extension); } } } this.path = path; } public boolean isRemoteAvailable() { return null != this.url || FileStatus.UPLOADED == this.fileStatus || FileStatus.DELETE_FAILED == this.fileStatus; } public void setFileStatus(FileStatus fileStatus) { this.fileStatus = fileStatus; } public FileStatus getFileStatus() { return this.fileStatus; } public void setOriginalFilename(String originalFilename) { this.originalFilename = originalFilename; } public String getOriginalFilename() { return this.originalFilename; } }