| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package org.apache.commons.compress.archivers.sevenz; |
| 20 |
|
| 21 |
import java.nio.file.attribute.FileTime; |
| 22 |
import java.util.Arrays; |
| 23 |
import java.util.Collections; |
| 24 |
import java.util.Date; |
| 25 |
import java.util.Iterator; |
| 26 |
import java.util.LinkedList; |
| 27 |
import java.util.Objects; |
| 28 |
|
| 29 |
import org.apache.commons.compress.archivers.ArchiveEntry; |
| 30 |
import org.apache.commons.io.file.attribute.FileTimes; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class SevenZArchiveEntry implements ArchiveEntry { |
| 39 |
|
| 40 |
static final SevenZArchiveEntry[] EMPTY_SEVEN_Z_ARCHIVE_ENTRY_ARRAY = {}; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
@Deprecated |
| 51 |
public static long javaTimeToNtfsTime(final Date date) { |
| 52 |
return FileTimes.toNtfsTime(date); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
@Deprecated |
| 64 |
public static Date ntfsTimeToJavaTime(final long ntfsTime) { |
| 65 |
return FileTimes.ntfsTimeToDate(ntfsTime); |
| 66 |
} |
| 67 |
|
| 68 |
private String name; |
| 69 |
private boolean hasStream; |
| 70 |
private boolean isDirectory; |
| 71 |
private boolean isAntiItem; |
| 72 |
private boolean hasCreationDate; |
| 73 |
private boolean hasLastModifiedDate; |
| 74 |
private boolean hasAccessDate; |
| 75 |
private FileTime creationDate; |
| 76 |
private FileTime lastModifiedDate; |
| 77 |
private FileTime accessDate; |
| 78 |
private boolean hasWindowsAttributes; |
| 79 |
private int windowsAttributes; |
| 80 |
private boolean hasCrc; |
| 81 |
private long crc; |
| 82 |
private long compressedCrc; |
| 83 |
private long size; |
| 84 |
private long compressedSize; |
| 85 |
private Iterable<? extends SevenZMethodConfiguration> contentMethods; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public SevenZArchiveEntry() { |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
public boolean equals(final Object obj) { |
| 95 |
if (this == obj) { |
| 96 |
return true; |
| 97 |
} |
| 98 |
if (obj == null || getClass() != obj.getClass()) { |
| 99 |
return false; |
| 100 |
} |
| 101 |
final SevenZArchiveEntry other = (SevenZArchiveEntry) obj; |
| 102 |
return Objects.equals(name, other.name) && hasStream == other.hasStream && isDirectory == other.isDirectory && isAntiItem == other.isAntiItem |
| 103 |
&& hasCreationDate == other.hasCreationDate && hasLastModifiedDate == other.hasLastModifiedDate && hasAccessDate == other.hasAccessDate |
| 104 |
&& Objects.equals(creationDate, other.creationDate) && Objects.equals(lastModifiedDate, other.lastModifiedDate) |
| 105 |
&& Objects.equals(accessDate, other.accessDate) && hasWindowsAttributes == other.hasWindowsAttributes |
| 106 |
&& windowsAttributes == other.windowsAttributes && hasCrc == other.hasCrc && crc == other.crc && compressedCrc == other.compressedCrc |
| 107 |
&& size == other.size && compressedSize == other.compressedSize && equalSevenZMethods(contentMethods, other.contentMethods); |
| 108 |
} |
| 109 |
|
| 110 |
private boolean equalSevenZMethods(final Iterable<? extends SevenZMethodConfiguration> c1, final Iterable<? extends SevenZMethodConfiguration> c2) { |
| 111 |
if (c1 == null) { |
| 112 |
return c2 == null; |
| 113 |
} |
| 114 |
if (c2 == null) { |
| 115 |
return false; |
| 116 |
} |
| 117 |
final Iterator<? extends SevenZMethodConfiguration> i2 = c2.iterator(); |
| 118 |
for (final SevenZMethodConfiguration element : c1) { |
| 119 |
if (!i2.hasNext() || !element.equals(i2.next())) { |
| 120 |
return false; |
| 121 |
} |
| 122 |
} |
| 123 |
return !i2.hasNext(); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public Date getAccessDate() { |
| 134 |
return FileTimes.toDate(getAccessTime()); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public FileTime getAccessTime() { |
| 145 |
if (hasAccessDate) { |
| 146 |
return accessDate; |
| 147 |
} |
| 148 |
throw new UnsupportedOperationException("The entry doesn't have this timestamp"); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
@Deprecated |
| 158 |
int getCompressedCrc() { |
| 159 |
return (int) compressedCrc; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
long getCompressedCrcValue() { |
| 169 |
return compressedCrc; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
long getCompressedSize() { |
| 178 |
return compressedSize; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public Iterable<? extends SevenZMethodConfiguration> getContentMethods() { |
| 197 |
return contentMethods; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
@Deprecated |
| 207 |
public int getCrc() { |
| 208 |
return (int) crc; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
public long getCrcValue() { |
| 218 |
return crc; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
public Date getCreationDate() { |
| 229 |
return FileTimes.toDate(getCreationTime()); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
public FileTime getCreationTime() { |
| 240 |
if (hasCreationDate) { |
| 241 |
return creationDate; |
| 242 |
} |
| 243 |
throw new UnsupportedOperationException("The entry doesn't have this timestamp"); |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
public boolean getHasAccessDate() { |
| 252 |
return hasAccessDate; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
public boolean getHasCrc() { |
| 265 |
return hasCrc; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
public boolean getHasCreationDate() { |
| 274 |
return hasCreationDate; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
public boolean getHasLastModifiedDate() { |
| 283 |
return hasLastModifiedDate; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public boolean getHasWindowsAttributes() { |
| 292 |
return hasWindowsAttributes; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
@Override |
| 303 |
public Date getLastModifiedDate() { |
| 304 |
return FileTimes.toDate(getLastModifiedTime()); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
public FileTime getLastModifiedTime() { |
| 315 |
if (hasLastModifiedDate) { |
| 316 |
return lastModifiedDate; |
| 317 |
} |
| 318 |
throw new UnsupportedOperationException("The entry doesn't have this timestamp"); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
@Override |
| 331 |
public String getName() { |
| 332 |
return name; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
@Override |
| 341 |
public long getSize() { |
| 342 |
return size; |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
public int getWindowsAttributes() { |
| 351 |
return windowsAttributes; |
| 352 |
} |
| 353 |
|
| 354 |
@Override |
| 355 |
public int hashCode() { |
| 356 |
final String n = getName(); |
| 357 |
return n == null ? 0 : n.hashCode(); |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
public boolean hasStream() { |
| 369 |
return hasStream; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
public boolean isAntiItem() { |
| 378 |
return isAntiItem; |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
@Override |
| 387 |
public boolean isDirectory() { |
| 388 |
return isDirectory; |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
public boolean isEmptyStream() { |
| 401 |
return !hasStream; |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
public void setAccessDate(final Date accessDate) { |
| 411 |
setAccessTime(FileTimes.toFileTime(accessDate)); |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
public void setAccessDate(final long ntfsAccessDate) { |
| 420 |
this.accessDate = FileTimes.ntfsTimeToFileTime(ntfsAccessDate); |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
public void setAccessTime(final FileTime time) { |
| 430 |
hasAccessDate = time != null; |
| 431 |
if (hasAccessDate) { |
| 432 |
this.accessDate = time; |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
public void setAntiItem(final boolean isAntiItem) { |
| 442 |
this.isAntiItem = isAntiItem; |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
@Deprecated |
| 452 |
void setCompressedCrc(final int crc) { |
| 453 |
this.compressedCrc = crc; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
void setCompressedCrcValue(final long crc) { |
| 463 |
this.compressedCrc = crc; |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
void setCompressedSize(final long size) { |
| 472 |
this.compressedSize = size; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
public void setContentMethods(final Iterable<? extends SevenZMethodConfiguration> methods) { |
| 491 |
if (methods != null) { |
| 492 |
final LinkedList<SevenZMethodConfiguration> l = new LinkedList<>(); |
| 493 |
methods.forEach(l::addLast); |
| 494 |
contentMethods = Collections.unmodifiableList(l); |
| 495 |
} else { |
| 496 |
contentMethods = null; |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
public void setContentMethods(final SevenZMethodConfiguration... methods) { |
| 516 |
setContentMethods(Arrays.asList(methods)); |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
@Deprecated |
| 526 |
public void setCrc(final int crc) { |
| 527 |
this.crc = crc; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
public void setCrcValue(final long crc) { |
| 537 |
this.crc = crc; |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
public void setCreationDate(final Date creationDate) { |
| 547 |
setCreationTime(FileTimes.toFileTime(creationDate)); |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
public void setCreationDate(final long ntfsCreationDate) { |
| 556 |
this.creationDate = FileTimes.ntfsTimeToFileTime(ntfsCreationDate); |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
public void setCreationTime(final FileTime time) { |
| 566 |
hasCreationDate = time != null; |
| 567 |
if (hasCreationDate) { |
| 568 |
this.creationDate = time; |
| 569 |
} |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
public void setDirectory(final boolean isDirectory) { |
| 578 |
this.isDirectory = isDirectory; |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
public void setHasAccessDate(final boolean hasAcessDate) { |
| 587 |
this.hasAccessDate = hasAcessDate; |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
public void setHasCrc(final boolean hasCrc) { |
| 596 |
this.hasCrc = hasCrc; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
public void setHasCreationDate(final boolean hasCreationDate) { |
| 605 |
this.hasCreationDate = hasCreationDate; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
public void setHasLastModifiedDate(final boolean hasLastModifiedDate) { |
| 614 |
this.hasLastModifiedDate = hasLastModifiedDate; |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
public void setHasStream(final boolean hasStream) { |
| 623 |
this.hasStream = hasStream; |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
public void setHasWindowsAttributes(final boolean hasWindowsAttributes) { |
| 632 |
this.hasWindowsAttributes = hasWindowsAttributes; |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
public void setLastModifiedDate(final Date lastModifiedDate) { |
| 642 |
setLastModifiedTime(FileTimes.toFileTime(lastModifiedDate)); |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
public void setLastModifiedDate(final long ntfsLastModifiedDate) { |
| 651 |
this.lastModifiedDate = FileTimes.ntfsTimeToFileTime(ntfsLastModifiedDate); |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
public void setLastModifiedTime(final FileTime time) { |
| 661 |
hasLastModifiedDate = time != null; |
| 662 |
if (hasLastModifiedDate) { |
| 663 |
this.lastModifiedDate = time; |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
public void setName(final String name) { |
| 673 |
this.name = name; |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
public void setSize(final long size) { |
| 682 |
this.size = size; |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
public void setWindowsAttributes(final int windowsAttributes) { |
| 691 |
this.windowsAttributes = windowsAttributes; |
| 692 |
} |
| 693 |
} |