/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Portions Copyright 2012 Jens Elkner.
*/
/**
* A {@link FilterInputStream} for Opengrok crossfiles.
* It uses a {@link BufferedInputStream} or {@link GZIPInputStream} as
* underlying stream to provide the required functionality. So there is usually
* no need to wrap it into another BufferedInputStream etc. .
*
* @see BufferedInputStream
* @see GZIPInputStream
*
* @author Jens Elkner
* @version $Revision$
*/
private boolean uncompress;
private boolean canClose;
/**
* Create a new InputStream from the given crossfile. The header gets read
* automatically and thus internal cursor points to the start of the data
* section of the crossfile, when this method returns.
*
* @param file file to read.
* @param uncompress if {@code true} crossfile data gets uncompressed on
* the fly if they are compressed.
* @throws IOException on read error or if the given file is not a crossfile
*/
super(null);
try {
in = this.uncompress
} catch (IOException e) {
} else {
}
}
canClose = true;
}
/**
* Get the header of the crossfile beeing read.
* @return the crossfile header
*/
return header;
}
/**
* Convinience method to check, whether the wrapped crossfile contains
* compressed data.
* @return {@code true} if data section is compressed.
* @see XrefHeader#isCompressed()
* @see #getHeader()
*/
public boolean isCompressed() {
return header.isCompressed();
}
/**
* Convinience method to get the Genre of data provided by this stream.
* @return the data's genre.
* @see XrefHeader#getGenre()
* @see #getHeader()
*/
}
/**
* Get the file from which this stream has been created.
* @return the origin of this stream
*/
return file;
}
/**
* Dump all data not yet read to the given output stream.
* @param out where to dump remaining data.
* @throws IOException
*/
throw new IllegalArgumentException("null output stream not allowed");
}
byte[] buf =
int len = 0;
}
}
/**
* Dump all data not yet read to the given writer. The constructor for this
* instance should have been called with on-the-fly uncompression enabled.
* If not and the data of the stream are compressed, it is tried to switch
* over to on-the-fly uncompression, but obviously this will fail with an
* IOException, if any data have been read from this stream already.
*
* @param out where to write data.
* @throws IOException on read error
* @see XrefInputStream#XrefInputStream(File, boolean)
*/
throw new IllegalArgumentException("null output stream not allowed");
}
+ file + " (wasn't specified in constructor)");
}
int len = 0;
canClose = false; // avoid that isr.close() closes in as well
try {
}
} finally {
canClose = true;
}
}
/**
* Convinience method to dump a crossfile to the given writer..
*
* @param file crossfile to dump.
* @param out dump destination.
* @param script if {@code true} the javascript snippet
* {@code O.lines=$num; O.createLinenums();} gets emitted to the writer
* first.
* @return {@code true} on success.
*/
return false;
}
try {
if (script) {
}
return true;
} catch (Exception e) {
} finally {
}
return false;
}
/**
* {@inheritDoc}
*/
if (!canClose) {
return;
}
}
/**
* Dump an opengrok cross file.
* @param args opengrok crossfile name
*/
return;
}
try {
} catch (IOException e) {
} finally {
}
}
}