Home | History | Annotate | Download | only in changes
      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     Change(final String pFilename, final int type) {
     50         if(pFilename == null) {
     51             throw new NullPointerException();
     52         }
     53         this.targetFile = pFilename;
     54         this.type = type;
     55         this.input = null;
     56         this.entry = null;
     57         this.replaceMode = true;
     58     }
     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     Change(final ArchiveEntry pEntry, final InputStream pInput, final boolean replace) {
     67         if(pEntry == null || pInput == null) {
     68             throw new NullPointerException();
     69         }
     70         this.entry = pEntry;
     71         this.input = pInput;
     72         type = TYPE_ADD;
     73         targetFile = null;
     74         this.replaceMode = replace;
     75     }
     76 
     77     ArchiveEntry getEntry() {
     78         return entry;
     79     }
     80 
     81     InputStream getInput() {
     82         return input;
     83     }
     84 
     85     String targetFile() {
     86         return targetFile;
     87     }
     88 
     89     int type() {
     90         return type;
     91     }
     92 
     93     boolean isReplaceMode() {
     94         return replaceMode;
     95     }
     96 }
     97