@@ -0,0 +1,2310 @@
+/*-%0A * Copyright (c) 2012 Red Hat, Inc.%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 */%0Apackage org.fedoraproject.javadeptools;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.lang.ProcessBuilder.Redirect;%0A%0Aimport org.apache.commons.compress.archivers.ArchiveEntry;%0Aimport org.apache.commons.compress.archivers.ArchiveInputStream;%0Aimport org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;%0A%0A/**%0A * A class for reading RPM package as an archive.%0A *%0A * @author Mikolaj Izdebski%0A */%0Aclass RpmArchiveInputStream extends ArchiveInputStream %7B%0A  private final Process child;%0A  private static final File bitBucket = new File(%22/dev/null%22);%0A  private final ArchiveInputStream in;%0A%0A  public RpmArchiveInputStream(File rpm) throws IOException %7B%0A    ProcessBuilder pb = new ProcessBuilder(%22rpm2cpio%22);%0A    pb.redirectInput(Redirect.from(rpm));%0A    pb.redirectError(bitBucket);%0A%0A    child = pb.start();%0A    InputStream childIn = child.getInputStream();%0A    in = new CpioArchiveInputStream(childIn);%0A  %7D%0A%0A  public void close() throws IOException %7B%0A    in.close();%0A    // If rpm2cpio hasn't terminated yet it should get SIGPIPE now.%0A    try %7B%0A      int status = child.waitFor();%0A      if (status != 0)%0A        throw new IOException(%22rpm2cpio exited with exit status %22 + status);%0A    %7D catch (InterruptedException e) %7B%0A      throw new IOException(%22Interruped while reaping child process%22, e);%0A    %7D%0A  %7D%0A%0A  public ArchiveEntry getNextEntry() throws IOException %7B%0A    return in.getNextEntry();%0A  %7D%0A%0A  public int read() throws IOException %7B%0A    return in.read();%0A  %7D%0A%0A  public int read(byte%5B%5D buf) throws IOException %7B%0A    return in.read(buf);%0A  %7D%0A%0A  public int read(byte%5B%5D buf, int off, int len) throws IOException %7B%0A    return in.read(buf, off, len);%0A  %7D%0A%7D%0A

Implement RpmArchiveInputStream