@@ -0,0 +1,2314 @@
+/* Copyright 2013 hbz, Pascal Christoph.%0A *%0A *  Licensed under the Apache License, Version 2.0 the %22License%22;%0A *  you may not use this file except in compliance with the License.%0A *  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *  Unless required by applicable law or agreed to in writing, software%0A *  distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *  See the License for the specific language governing permissions and%0A *  limitations under the License.%0A */%0A%0Apackage org.culturegraph.mf.stream.reader;%0A%0Aimport java.io.FileNotFoundException;%0Aimport java.io.IOException;%0Aimport java.io.Reader;%0Aimport java.io.StringReader;%0A%0Aimport org.apache.commons.compress.archivers.tar.TarArchiveEntry;%0Aimport org.apache.commons.compress.archivers.tar.TarArchiveInputStream;%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.apache.commons.io.input.ReaderInputStream;%0Aimport org.culturegraph.mf.framework.DefaultObjectPipe;%0Aimport org.culturegraph.mf.framework.ObjectReceiver;%0Aimport org.culturegraph.mf.framework.annotations.Description;%0Aimport org.culturegraph.mf.framework.annotations.In;%0Aimport org.culturegraph.mf.framework.annotations.Out;%0A%0A/**%0A * Opens (aka 'untar') a tar archive and passes every entry .%0A *%0A * @author Pascal Christoph (dr0i)%0A */%0A@Description(%22Opens a tar archive and passes every entry.%22)%0A@In(Reader.class)%0A@Out(Reader.class)%0Apublic class TarReader extends DefaultObjectPipe%3CReader, ObjectReceiver%3CReader%3E%3E %7B%0A%09@Override%0A%09public void process(final Reader reader) %7B%0A%09%09TarArchiveInputStream tarInputStream = null;%0A%09%09try %7B%0A%09%09%09tarInputStream = new TarArchiveInputStream(new ReaderInputStream(reader));%0A%09%09%09TarArchiveEntry entry = null;%0A%09%09%09while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) %7B%0A%09%09%09%09if (!entry.isDirectory()) %7B%0A%09%09%09%09%09final byte%5B%5D buffer = new byte%5B(int) entry.getSize()%5D;%0A%09%09%09%09%09while ((tarInputStream.read(buffer)) %3E 0) %7B%0A%09%09%09%09%09%09getReceiver().process(new StringReader(new String(buffer)));%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09tarInputStream.close();%0A%09%09%7D catch (final FileNotFoundException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D catch (final IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D finally %7B%0A%09%09%09IOUtils.closeQuietly(tarInputStream);%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add tar reader