Torsten Curdt | ca16539 | 2008-07-10 10:17:44 +0000 | [diff] [blame] | 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.archivers.zip; |
| 20 | |
| 21 | /** |
| 22 | * Simple placeholder for all those extra fields we don't want to deal with. <p> |
| 23 | * |
| 24 | * Assumes local file data and central directory entries are identical - unless |
| 25 | * told the opposite.</p> |
Torsten Curdt | ca16539 | 2008-07-10 10:17:44 +0000 | [diff] [blame] | 26 | */ |
| 27 | public class UnrecognizedExtraField |
| 28 | implements ZipExtraField |
| 29 | { |
| 30 | /** |
| 31 | * Extra field data in central directory - without Header-ID or length |
| 32 | * specifier. |
| 33 | * |
| 34 | * @since 1.1 |
| 35 | */ |
| 36 | private byte[] m_centralData; |
| 37 | |
| 38 | /** |
| 39 | * The Header-ID. |
| 40 | * |
| 41 | * @since 1.1 |
| 42 | */ |
| 43 | private ZipShort m_headerID; |
| 44 | |
| 45 | /** |
| 46 | * Extra field data in local file data - without Header-ID or length |
| 47 | * specifier. |
| 48 | * |
| 49 | * @since 1.1 |
| 50 | */ |
| 51 | private byte[] m_localData; |
| 52 | |
| 53 | /** |
| 54 | * Set the central directory data |
| 55 | * |
| 56 | * @param centralData the central directory data |
| 57 | */ |
| 58 | public void setCentralDirectoryData( final byte[] centralData ) |
| 59 | { |
| 60 | m_centralData = centralData; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Set the header ID. |
| 65 | * |
| 66 | * @param headerID the header ID |
| 67 | */ |
Torsten Curdt | ab9ebfc | 2009-01-12 11:15:34 +0000 | [diff] [blame^] | 68 | public void setHeaderId( final ZipShort headerID ) |
Torsten Curdt | ca16539 | 2008-07-10 10:17:44 +0000 | [diff] [blame] | 69 | { |
| 70 | m_headerID = headerID; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Set the local file data. |
| 75 | * |
| 76 | * @param localData the local file data |
| 77 | */ |
| 78 | public void setLocalFileDataData( final byte[] localData ) |
| 79 | { |
| 80 | m_localData = localData; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get the central directory data. |
| 85 | * |
| 86 | * @return the central directory data. |
| 87 | */ |
| 88 | public byte[] getCentralDirectoryData() |
| 89 | { |
| 90 | if( m_centralData != null ) |
| 91 | { |
| 92 | return m_centralData; |
| 93 | } |
| 94 | return getLocalFileDataData(); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Get the length of the central directory in bytes. |
| 99 | * |
| 100 | * @return the length of the central directory in bytes. |
| 101 | */ |
| 102 | public ZipShort getCentralDirectoryLength() |
| 103 | { |
| 104 | if( m_centralData != null ) |
| 105 | { |
| 106 | return new ZipShort( m_centralData.length ); |
| 107 | } |
| 108 | return getLocalFileDataLength(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Get the HeaderID. |
| 113 | * |
| 114 | * @return the HeaderID |
| 115 | */ |
Torsten Curdt | ab9ebfc | 2009-01-12 11:15:34 +0000 | [diff] [blame^] | 116 | public ZipShort getHeaderId() |
Torsten Curdt | ca16539 | 2008-07-10 10:17:44 +0000 | [diff] [blame] | 117 | { |
| 118 | return m_headerID; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Get the local file data. |
| 123 | * |
| 124 | * @return the local file data |
| 125 | */ |
| 126 | public byte[] getLocalFileDataData() |
| 127 | { |
| 128 | return m_localData; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Get the length of local file data in bytes. |
| 133 | * |
| 134 | * @return the length of local file data in bytes |
| 135 | */ |
| 136 | public ZipShort getLocalFileDataLength() |
| 137 | { |
| 138 | return new ZipShort( m_localData.length ); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Parse LocalFiledata out of supplied buffer. |
| 143 | * |
| 144 | * @param buffer the buffer to use |
| 145 | * @param offset the offset into buffer |
| 146 | * @param length then length of data |
| 147 | */ |
| 148 | public void parseFromLocalFileData( final byte[] buffer, |
| 149 | final int offset, |
| 150 | final int length ) |
| 151 | { |
| 152 | final byte[] fileData = new byte[ length ]; |
| 153 | System.arraycopy( buffer, offset, fileData, 0, length ); |
| 154 | setLocalFileDataData( fileData ); |
| 155 | } |
| 156 | } |