import java.util.zip.*;
import java.util.*;
import java.io.*;

class Main {

	interface ZipContent {}

	static class ZipText implements ZipContent {
		private String name;
		private String contents;

		public ZipText(String name, String contents) {
			this.name = name;
			this.contents = contents;
		}
		
		@Override
		public String toString() {
			return name + " { " + contents + " }";
		}
	}

    static class ZipUnknown implements ZipContent {
		private String name;

		public ZipUnknown(String name) {
			this.name = name;
		}
		
		@Override
		public String toString() {
			return name + " (UNKNOWN)";
		}
	}

	static class ZipContents implements ZipContent {
		private String name;
		private List<ZipContent> contents;
		private String indentContents;

		private String getStringIndent(int indent) {
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < indent; i++) {
				sb.append("  ");
			}
			return sb.toString(); 
		}

		private ZipContents(String name, List<ZipContent> contents, int indent) {
			this.name = name;
			this.contents = contents;
			this.indentContents = getStringIndent(indent + 1);
		}

		private static ZipContents readZipStream(String zipName, InputStream is, int indent) throws Exception {
			List<ZipContent> contents = new ArrayList<>();

			// Closing ZipInputStream would propagate to InputStream. Intentionally not doing so.
			ZipInputStream zis = new ZipInputStream(is);
			ZipEntry ze;
			while((ze = zis.getNextEntry()) != null) {
				String entryName = ze.getName();
				String suffix = entryName.substring(entryName.lastIndexOf('.') + 1).toLowerCase();
				switch(suffix) {
				case "zip":
					contents.add(readZipStream(entryName, zis, indent + 1));
					break;
				case "txt":
					Scanner s = new Scanner(zis).useDelimiter("\\A");
					String result = s.hasNext() ? s.next() : "";
					// Trim to match specification from forum.root.cz.
					contents.add(new ZipText(entryName, result.trim()));
					break;
				default:
					contents.add(new ZipUnknown(entryName));
				}
			}

			return new ZipContents(zipName, contents, indent);
		}

		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append(name);
			for (ZipContent oneFile: contents) {
				sb.append("\n");
				sb.append(indentContents);
				sb.append(oneFile.toString());
			}
			
			return sb.toString();
		}
	}

	public static void main(String[] args) throws Exception {
		if (args.length != 1) {
			System.err.println("Specify zip file!");
			return;
		}
		String fileName = args[0];
		try (InputStream is = new FileInputStream(fileName)) {
			ZipContents zc = ZipContents.readZipStream(fileName, is, 0);
			System.out.println(zc.toString());
		}
	}
}
