|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.commons.compress.archivers.lha; |
| 21 | + |
| 22 | +import java.time.ZoneOffset; |
| 23 | +import java.util.Date; |
| 24 | +import java.util.Optional; |
| 25 | + |
| 26 | +import org.apache.commons.compress.archivers.ArchiveEntry; |
| 27 | + |
| 28 | +/** |
| 29 | + * Represents an entry in a LHA archive. |
| 30 | + * |
| 31 | + * @since 1.29 |
| 32 | + */ |
| 33 | +public class LhaArchiveEntry implements ArchiveEntry { |
| 34 | + private String name; |
| 35 | + private boolean directory; |
| 36 | + private long size; |
| 37 | + private Date lastModifiedDate; |
| 38 | + private long compressedSize; |
| 39 | + private String compressionMethod; |
| 40 | + private int crcValue; |
| 41 | + private Optional<Integer> osId = Optional.empty(); |
| 42 | + private Optional<Integer> unixPermissionMode = Optional.empty(); |
| 43 | + private Optional<Integer> unixUserId = Optional.empty(); |
| 44 | + private Optional<Integer> unixGroupId = Optional.empty(); |
| 45 | + private Optional<Integer> msdosFileAttributes = Optional.empty(); |
| 46 | + private Optional<Integer> headerCrc = Optional.empty(); |
| 47 | + |
| 48 | + public LhaArchiveEntry() { |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public String toString() { |
| 53 | + StringBuffer sb = new StringBuffer().append("LhaArchiveEntry[") |
| 54 | + .append("name=").append(name) |
| 55 | + .append(",directory=").append(directory) |
| 56 | + .append(",size=").append(size) |
| 57 | + .append(",lastModifiedDate=").append(lastModifiedDate == null ? "" : lastModifiedDate.toInstant().atZone(ZoneOffset.UTC).toString()) |
| 58 | + .append(",compressedSize=").append(compressedSize) |
| 59 | + .append(",compressionMethod=").append(compressionMethod) |
| 60 | + .append(",crcValue=").append(String.format("0x%04x", crcValue)); |
| 61 | + |
| 62 | + if (osId.isPresent()) { |
| 63 | + sb.append(",osId=").append(osId.get()); |
| 64 | + } |
| 65 | + |
| 66 | + if (unixPermissionMode.isPresent()) { |
| 67 | + sb.append(",unixPermissionMode=").append(String.format("%03o", unixPermissionMode.get())); |
| 68 | + } |
| 69 | + |
| 70 | + if (msdosFileAttributes.isPresent()) { |
| 71 | + sb.append(",msdosFileAttributes=").append(String.format("%04x", msdosFileAttributes.get())); |
| 72 | + } |
| 73 | + |
| 74 | + if (headerCrc.isPresent()) { |
| 75 | + sb.append(",headerCrc=").append(String.format("0x%04x", headerCrc.get())); |
| 76 | + } |
| 77 | + |
| 78 | + return sb.append("]").toString(); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public String getName() { |
| 83 | + return name; |
| 84 | + } |
| 85 | + |
| 86 | + public void setName(String name) { |
| 87 | + this.name = name; |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public long getSize() { |
| 92 | + return size; |
| 93 | + } |
| 94 | + |
| 95 | + public void setSize(long size) { |
| 96 | + this.size = size; |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public Date getLastModifiedDate() { |
| 101 | + return lastModifiedDate; |
| 102 | + } |
| 103 | + |
| 104 | + public void setLastModifiedDate(Date lastModifiedDate) { |
| 105 | + this.lastModifiedDate = lastModifiedDate; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Returns the compressed size of this entry. |
| 110 | + * |
| 111 | + * @return the compressed size |
| 112 | + */ |
| 113 | + public long getCompressedSize() { |
| 114 | + return compressedSize; |
| 115 | + } |
| 116 | + |
| 117 | + public void setCompressedSize(long compressedSize) { |
| 118 | + this.compressedSize = compressedSize; |
| 119 | + } |
| 120 | + |
| 121 | + public void setDirectory(boolean directory) { |
| 122 | + this.directory = directory; |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public boolean isDirectory() { |
| 127 | + return directory; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Returns the compression method of this entry. |
| 132 | + * |
| 133 | + * @return the compression method |
| 134 | + */ |
| 135 | + public String getCompressionMethod() { |
| 136 | + return compressionMethod; |
| 137 | + } |
| 138 | + |
| 139 | + public void setCompressionMethod(String compressionMethod) { |
| 140 | + this.compressionMethod = compressionMethod; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Returns the CRC-16 checksum of the uncompressed data of this entry. |
| 145 | + * |
| 146 | + * @return CRC-16 checksum of the uncompressed data |
| 147 | + */ |
| 148 | + public int getCrcValue() { |
| 149 | + return crcValue; |
| 150 | + } |
| 151 | + |
| 152 | + public void setCrcValue(int crc) { |
| 153 | + this.crcValue = crc; |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * Returns the operating system id if available for this entry. |
| 158 | + * |
| 159 | + * @return operating system id if available |
| 160 | + */ |
| 161 | + public Optional<Integer> getOsId() { |
| 162 | + return osId; |
| 163 | + } |
| 164 | + |
| 165 | + public void setOsId(Optional<Integer> osId) { |
| 166 | + this.osId = osId; |
| 167 | + } |
| 168 | + |
| 169 | + public Optional<Integer> getUnixPermissionMode() { |
| 170 | + return unixPermissionMode; |
| 171 | + } |
| 172 | + |
| 173 | + public void setUnixPermissionMode(Optional<Integer> unixPermissionMode) { |
| 174 | + this.unixPermissionMode = unixPermissionMode; |
| 175 | + } |
| 176 | + |
| 177 | + public Optional<Integer> getUnixUserId() { |
| 178 | + return unixUserId; |
| 179 | + } |
| 180 | + |
| 181 | + public void setUnixUserId(Optional<Integer> unixUserId) { |
| 182 | + this.unixUserId = unixUserId; |
| 183 | + } |
| 184 | + |
| 185 | + public Optional<Integer> getUnixGroupId() { |
| 186 | + return unixGroupId; |
| 187 | + } |
| 188 | + |
| 189 | + public void setUnixGroupId(Optional<Integer> unixGroupId) { |
| 190 | + this.unixGroupId = unixGroupId; |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * Returns the MS-DOS file attributes if available for this entry. |
| 195 | + * |
| 196 | + * @return MS-DOS file attributes if available |
| 197 | + */ |
| 198 | + public Optional<Integer> getMsdosFileAttributes() { |
| 199 | + return msdosFileAttributes; |
| 200 | + } |
| 201 | + |
| 202 | + public void setMsdosFileAttributes(Optional<Integer> msdosFileAttributes) { |
| 203 | + this.msdosFileAttributes = msdosFileAttributes; |
| 204 | + } |
| 205 | + |
| 206 | + /** |
| 207 | + * Don't expose the header CRC publicly, as it is of no interest to most users. |
| 208 | + */ |
| 209 | + Optional<Integer> getHeaderCrc() { |
| 210 | + return headerCrc; |
| 211 | + } |
| 212 | + |
| 213 | + void setHeaderCrc(Optional<Integer> headerCrc) { |
| 214 | + this.headerCrc = headerCrc; |
| 215 | + } |
| 216 | +} |
0 commit comments