You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2009/04/23 13:06:36 UTC
Re: svn commit: r767804 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
On 23/04/2009, grobmeier@apache.org <gr...@apache.org> wrote:
> Author: grobmeier
> Date: Thu Apr 23 05:30:06 2009
> New Revision: 767804
>
> URL: http://svn.apache.org/viewvc?rev=767804&view=rev
> Log:
> added javadocs
And reflowed some code lines - but why?
They were not all that long, and IMO the new version is harder to read
> Modified:
> commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
>
> Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
> URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=767804&r1=767803&r2=767804&view=diff
> ==============================================================================
> --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java (original)
> +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java Thu Apr 23 05:30:06 2009
> @@ -36,18 +36,26 @@
> private final InputStream input;
> private long offset = 0;
> private boolean closed;
> +
> /*
> * If getNextEnxtry has been called, the entry metadata is stored in
> * currentEntry.
> */
> private ArArchiveEntry currentEntry = null;
> +
> /*
> * The offset where the current entry started. -1 if no entry has been
> * called
> */
> private long entryOffset = -1;
>
> - public ArArchiveInputStream( final InputStream pInput ) {
> + /**
> + * Constructs an Ar input stream with the referenced stream
> + *
> + * @param pInput
> + * the ar input stream
> + */
> + public ArArchiveInputStream(final InputStream pInput) {
> input = pInput;
> closed = false;
> }
> @@ -74,15 +82,18 @@
> }
>
> if (offset == 0) {
> - final byte[] expected = ArchiveUtils.toAsciiBytes(ArArchiveEntry.HEADER);
> - final byte[] realized = new byte[expected.length];
> + final byte[] expected = ArchiveUtils
> + .toAsciiBytes(ArArchiveEntry.HEADER);
> + final byte[] realized = new byte[expected.length];
> final int read = read(realized);
> if (read != expected.length) {
> - throw new IOException("failed to read header. Occured at byte: " + getCount());
> + throw new IOException(
> + "failed to read header. Occured at byte: " + getCount());
> }
> for (int i = 0; i < expected.length; i++) {
> if (expected[i] != realized[i]) {
> - throw new IOException("invalid header " + ArchiveUtils.toAsciiString(realized));
> + throw new IOException("invalid header "
> + + ArchiveUtils.toAsciiString(realized));
> }
> }
> }
> @@ -113,37 +124,53 @@
> read(length);
>
> {
> - final byte[] expected = ArchiveUtils.toAsciiBytes(ArArchiveEntry.TRAILER);
> - final byte[] realized = new byte[expected.length];
> + final byte[] expected = ArchiveUtils
> + .toAsciiBytes(ArArchiveEntry.TRAILER);
> + final byte[] realized = new byte[expected.length];
> final int read = read(realized);
> if (read != expected.length) {
> - throw new IOException("failed to read entry header. Occured at byte: " + getCount());
> + throw new IOException(
> + "failed to read entry header. Occured at byte: "
> + + getCount());
> }
> for (int i = 0; i < expected.length; i++) {
> if (expected[i] != realized[i]) {
> - throw new IOException("invalid entry header. not read the content? Occured at byte: " + getCount());
> + throw new IOException(
> + "invalid entry header. not read the content? Occured at byte: "
> + + getCount());
> }
> }
> }
>
> entryOffset = offset;
> -
> +
> // SVR4/GNU adds a trailing "/" to names
> - String temp=new String(name).trim(); // TODO is it correct to use the default charset here?
> - if (temp.endsWith("/")){
> - temp=temp.substring(0, temp.length()-1);
> - }
> - currentEntry = new ArArchiveEntry(temp, // TODO is it correct to use the default charset here?
> - Long.parseLong(new String(length)
> - .trim()));
> + String temp = new String(name).trim(); // TODO is it correct to use the
> + // default charset here?
> + if (temp.endsWith("/")) {
> + temp = temp.substring(0, temp.length() - 1);
> + }
> + currentEntry = new ArArchiveEntry(temp, // TODO is it correct to use the
> + // default charset here?
> + Long.parseLong(new String(length).trim()));
> return currentEntry;
> }
>
> -
> + /*
> + * (non-Javadoc)
> + *
> + * @see
> + * org.apache.commons.compress.archivers.ArchiveInputStream#getNextEntry()
> + */
> public ArchiveEntry getNextEntry() throws IOException {
> return getNextArEntry();
> }
>
> + /*
> + * (non-Javadoc)
> + *
> + * @see java.io.InputStream#close()
> + */
> public void close() throws IOException {
> if (!closed) {
> closed = true;
> @@ -152,6 +179,11 @@
> currentEntry = null;
> }
>
> + /*
> + * (non-Javadoc)
> + *
> + * @see java.io.InputStream#read(byte[], int, int)
> + */
> public int read(byte[] b, final int off, final int len) throws IOException {
> int toRead = len;
> if (currentEntry != null) {
> @@ -168,6 +200,16 @@
> return ret;
> }
>
> + /**
> + * Checks if the signature matches ASCII "!<arch>" followed by a single LF
> + * control character
> + *
> + * @param signature
> + * the bytes to check
> + * @param length
> + * the number of bytes to check
> + * @return true, if this stream is an Ar archive stream, false otherwise
> + */
> public static boolean matches(byte[] signature, int length) {
> // 3c21 7261 6863 0a3e
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r767804 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
Posted by Christian Grobmeier <gr...@gmail.com>.
On Thu, Apr 23, 2009 at 1:06 PM, sebb <se...@gmail.com> wrote:
> On 23/04/2009, grobmeier@apache.org <gr...@apache.org> wrote:
>> Author: grobmeier
>> Date: Thu Apr 23 05:30:06 2009
>> New Revision: 767804
>>
>> URL: http://svn.apache.org/viewvc?rev=767804&view=rev
>> Log:
>> added javadocs
>
> And reflowed some code lines - but why?
> They were not all that long, and IMO the new version is harder to read
ups... that wasn't my intented. I will correct this.
I remember that I did "autoformat" on my ide by fault and forgot to revert it.
Sorry!
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org