Skip to main content
summaryrefslogtreecommitdiffstats
blob: 622d9403457373eb134b9bbf339ec13ec7e1acd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.j2ee.commonarchivecore.internal.helpers;



import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonArchiveResourceHandler;
import org.eclipse.jst.j2ee.commonarchivecore.internal.File;
import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.ArchiveRuntimeException;


public class NestedArchiveIterator extends FileIteratorImpl {
	protected ZipInputStream zipInputStream;
	protected ZipEntry currentEntry;

	static class WrapperInputStream extends FilterInputStream {
		/**
		 * @param in
		 */
		public WrapperInputStream(InputStream in) {
			super(in);
			// TODO Auto-generated constructor stub
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.io.FilterInputStream#close()
		 */
		public void close() throws IOException {
			//do nothing because we want to prevent the clients from closing the zip
		}
	}

	/**
	 * NestedArchiveIterator constructor comment.
	 */
	public NestedArchiveIterator(List theFiles, ZipInputStream stream) {
		super(theFiles);
		zipInputStream = stream;
	}

	public InputStream getInputStream(File aFile) throws java.io.IOException, java.io.FileNotFoundException {
		if (!aFile.getURI().equals(currentEntry.getName()))
			throw new java.io.IOException(CommonArchiveResourceHandler.Internal_Error__Iterator_o_EXC_); // = "Internal Error: Iterator out of sync with zip entries"
		return new WrapperInputStream(zipInputStream);
	}

	public File next() {
		File next = super.next();
		try {
			do {
				currentEntry = zipInputStream.getNextEntry();
			} while (currentEntry.isDirectory());
		} catch (java.io.IOException ex) {
			throw new ArchiveRuntimeException(CommonArchiveResourceHandler.Error_iterating_the_archiv_EXC_, ex); // = "Error iterating the archive"
		}
		return next;
	}


}

Back to the top