| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Change |
|
| 1.7142857142857142;1,714 |
| 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 | * http://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 | package org.apache.commons.compress.changes; | |
| 20 | ||
| 21 | import java.io.InputStream; | |
| 22 | ||
| 23 | import org.apache.commons.compress.archivers.ArchiveEntry; | |
| 24 | ||
| 25 | /** | |
| 26 | * Change holds meta information about a change. | |
| 27 | * | |
| 28 | * @Immutable | |
| 29 | */ | |
| 30 | class Change { | |
| 31 | private final String targetFile; // entry name to delete | |
| 32 | private final ArchiveEntry entry; // new entry to add | |
| 33 | private final InputStream input; // source for new entry | |
| 34 | private final boolean replaceMode; // change should replaceMode existing entries | |
| 35 | ||
| 36 | // Type of change | |
| 37 | private final int type; | |
| 38 | // Possible type values | |
| 39 | static final int TYPE_DELETE = 1; | |
| 40 | static final int TYPE_ADD = 2; | |
| 41 | static final int TYPE_MOVE = 3; // NOT USED | |
| 42 | static final int TYPE_DELETE_DIR = 4; | |
| 43 | ||
| 44 | /** | |
| 45 | * Constructor. Takes the filename of the file to be deleted | |
| 46 | * from the stream as argument. | |
| 47 | * @param pFilename the filename of the file to delete | |
| 48 | */ | |
| 49 | 28 | Change(final String pFilename, int type) { |
| 50 | 28 | if(pFilename == null) { |
| 51 | 0 | throw new NullPointerException(); |
| 52 | } | |
| 53 | 28 | this.targetFile = pFilename; |
| 54 | 28 | this.type = type; |
| 55 | 28 | this.input = null; |
| 56 | 28 | this.entry = null; |
| 57 | 28 | this.replaceMode = true; |
| 58 | 28 | } |
| 59 | ||
| 60 | /** | |
| 61 | * Construct a change which adds an entry. | |
| 62 | * | |
| 63 | * @param pEntry the entry details | |
| 64 | * @param pInput the InputStream for the entry data | |
| 65 | */ | |
| 66 | 19 | Change(final ArchiveEntry pEntry, final InputStream pInput, boolean replace) { |
| 67 | 19 | if(pEntry == null || pInput == null) { |
| 68 | 0 | throw new NullPointerException(); |
| 69 | } | |
| 70 | 19 | this.entry = pEntry; |
| 71 | 19 | this.input = pInput; |
| 72 | 19 | type = TYPE_ADD; |
| 73 | 19 | targetFile = null; |
| 74 | 19 | this.replaceMode = replace; |
| 75 | 19 | } |
| 76 | ||
| 77 | ArchiveEntry getEntry() { | |
| 78 | 41 | return entry; |
| 79 | } | |
| 80 | ||
| 81 | InputStream getInput() { | |
| 82 | 33 | return input; |
| 83 | } | |
| 84 | ||
| 85 | String targetFile() { | |
| 86 | 268 | return targetFile; |
| 87 | } | |
| 88 | ||
| 89 | int type() { | |
| 90 | 372 | return type; |
| 91 | } | |
| 92 | ||
| 93 | boolean isReplaceMode() { | |
| 94 | 16 | return replaceMode; |
| 95 | } | |
| 96 | } |