comparison src/org/tmatesoft/hg/internal/DataAccess.java @ 397:5e95b0da26f2 smartgit3

Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 23 Feb 2012 15:31:57 +0100
parents b413b16d10a5
children fdc1db8f7f61
comparison
equal deleted inserted replaced
393:728708de3597 397:5e95b0da26f2
1 /* 1 /*
2 * Copyright (c) 2010-2011 TMate Software Ltd 2 * Copyright (c) 2010-2012 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
44 // nop, empty instance is always in the initial state 44 // nop, empty instance is always in the initial state
45 return this; 45 return this;
46 } 46 }
47 // absolute positioning 47 // absolute positioning
48 public void seek(int offset) throws IOException { 48 public void seek(int offset) throws IOException {
49 throw new UnsupportedOperationException(); 49 if (offset == 0) {
50 // perfectly OK for the "empty slice" instance
51 return;
52 }
53 throw new IOException(String.format("No data, can't seek %d bytes", offset));
50 } 54 }
51 // relative positioning 55 // relative positioning
52 public void skip(int bytes) throws IOException { 56 public void skip(int bytes) throws IOException {
53 throw new UnsupportedOperationException(); 57 if (bytes == 0) {
58 return;
59 }
60 throw new IOException(String.format("No data, can't skip %d bytes", bytes));
54 } 61 }
55 // shall be called once this object no longer needed 62 // shall be called once this object no longer needed
56 public void done() { 63 public void done() {
57 // no-op in this empty implementation 64 // no-op in this empty implementation
58 } 65 }
67 int i1 = b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); 74 int i1 = b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF);
68 int i2 = b[4] << 24 | (b[5] & 0xFF) << 16 | (b[6] & 0xFF) << 8 | (b[7] & 0xFF); 75 int i2 = b[4] << 24 | (b[5] & 0xFF) << 16 | (b[6] & 0xFF) << 8 | (b[7] & 0xFF);
69 return ((long) i1) << 32 | ((long) i2 & 0xFFFFFFFFl); 76 return ((long) i1) << 32 | ((long) i2 & 0xFFFFFFFFl);
70 } 77 }
71 public void readBytes(byte[] buf, int offset, int length) throws IOException { 78 public void readBytes(byte[] buf, int offset, int length) throws IOException {
72 throw new UnsupportedOperationException(); 79 if (length == 0) {
80 return;
81 }
82 throw new IOException(String.format("No data, can't read %d bytes", length));
73 } 83 }
74 // reads bytes into ByteBuffer, up to its limit or total data length, whichever smaller 84 // reads bytes into ByteBuffer, up to its limit or total data length, whichever smaller
75 // FIXME perhaps, in DataAccess paradigm (when we read known number of bytes, we shall pass specific byte count to read) 85 // FIXME perhaps, in DataAccess paradigm (when we read known number of bytes, we shall pass specific byte count to read)
76 public void readBytes(ByteBuffer buf) throws IOException { 86 public void readBytes(ByteBuffer buf) throws IOException {
77 // int toRead = Math.min(buf.remaining(), (int) length()); 87 // int toRead = Math.min(buf.remaining(), (int) length());