0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
8N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
0N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/Apackage org.opensolaris.opengrok.history;
0N/A
8N/Aimport java.io.ByteArrayInputStream;
8N/Aimport java.io.FileNotFoundException;
394N/Aimport java.io.IOException;
8N/Aimport java.io.InputStream;
1182N/A
8N/Aimport org.apache.commons.jrcs.diff.PatchFailedException;
8N/Aimport org.apache.commons.jrcs.rcs.Archive;
8N/Aimport org.apache.commons.jrcs.rcs.InvalidFileFormatException;
8N/Aimport org.apache.commons.jrcs.rcs.NodeNotFoundException;
8N/Aimport org.apache.commons.jrcs.rcs.ParseException;
1195N/Aimport org.opensolaris.opengrok.util.IOUtils;
0N/A
0N/A/**
0N/A * Virtualise RCS log as an input stream
0N/A */
0N/Apublic class RCSget extends InputStream {
1182N/A private InputStream stream;
1190N/A
8N/A /**
8N/A * Pass null in version to get current revision
1473N/A * @param file
1473N/A * @param version
1473N/A * @throws IOException
1473N/A * @throws FileNotFoundException
8N/A */
1473N/A public RCSget(String file, String version) throws IOException {
0N/A try {
521N/A Archive archive = new Archive(file);
8N/A Object[] lines;
1190N/A
460N/A if (version == null) {
460N/A lines = archive.getRevision(false);
460N/A } else {
8N/A lines = archive.getRevision(version, false);
0N/A }
1190N/A
8N/A StringBuilder sb = new StringBuilder();
8N/A for (int ii = 0; ii < lines.length; ++ii) {
8N/A sb.append((String)lines[ii]);
8N/A sb.append("\n");
8N/A }
1182N/A stream = new ByteArrayInputStream(sb.toString().getBytes());
0N/A } catch (ParseException e) {
1473N/A throw new IOException("Parse error: " + e.getMessage(), e);
0N/A } catch (InvalidFileFormatException e) {
1473N/A throw new IOException("Invalid RCS file format: " + e.getMessage(), e);
0N/A } catch (PatchFailedException e) {
1473N/A throw new IOException("Patch failed: " + e.getMessage(), e);
0N/A } catch (NodeNotFoundException e) {
1473N/A throw new IOException("Revision " + version + " not found: "
1473N/A + e.getMessage(), e);
0N/A }
8N/A }
1190N/A
1473N/A /**
1473N/A * {@inheritDoc}
1473N/A */
416N/A @Override
1473N/A public synchronized void reset() throws IOException {
427N/A stream.reset();
0N/A }
1190N/A
1473N/A /**
1473N/A * {@inheritDoc}
1473N/A */
416N/A @Override
1473N/A public void close() {
1195N/A IOUtils.close(stream);
8N/A }
1190N/A
1473N/A /**
1473N/A * {@inheritDoc}
1473N/A */
416N/A @Override
1473N/A public synchronized void mark(int readlimit) {
8N/A stream.mark(readlimit);
0N/A }
1190N/A
1473N/A /**
1473N/A * {@inheritDoc}
1473N/A */
416N/A @Override
8N/A public int read(byte[] buffer, int pos, int len) throws IOException {
8N/A return stream.read(buffer, pos, len);
8N/A }
1190N/A
1473N/A /**
1473N/A * {@inheritDoc}
1473N/A */
815N/A @Override
0N/A public int read() throws IOException {
0N/A throw new IOException("use a BufferedInputStream. just read() is not supported!");
0N/A }
0N/A}