1
/*******************************************************************************
2
* Copyright (c) 2007, 2009 Wind River Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Wind River Systems - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.text;
13
import java.io.IOException;
16
* A piece of text on a scratch file.
18
public class REDRun implements CharSequence {
29
public REDRun(IFileRider rider, int offset, int length) {
38
* @pre str.length() > 0
40
public REDRun(IFileRider rider, String str) throws IOException {
42
fLength = str.length();
43
fOffset = fRider.length();
45
fRider.writeChars(str, 0, fLength);
54
public REDRun(IFileRider rider, char[] buf, int off, int n) throws IOException {
57
fOffset = fRider.length();
59
fRider.writeChars(buf, off, n);
63
* @post return.length() == length()
65
public String asString() throws IOException {
67
char[] buf = new char[fLength];
69
fRider.readChars(buf);
70
retVal = new String(buf);
75
* Copy parts of run into char-array
76
* @param arr array to copy into
77
* @param from offset of arr to copy bytes to
78
* @param arrSize max offset of arr to write into
79
* @param myOff offset of run to start reading at
80
* @return the number of bytes copied
82
public int copyInto(char[] arr, int from, int arrSize, int myOff) throws IOException {
83
fRider.seek(fOffset + myOff);
84
int readAmount = Math.min(arrSize - from, fLength - myOff);
85
fRider.readChars(arr, from, readAmount);
90
* Append parts of run to a StringBuffer
91
* @param buffer StringBuffer to append to
92
* @param length number of characters to append
93
* @param myOff offset of run to start reading at
94
* @return the number of bytes appended
96
public int appendTo(StringBuffer buffer, int length, int myOff) throws IOException {
97
fRider.seek(fOffset + myOff);
98
int readAmount = Math.min(length, fLength - myOff);
99
fRider.readChars(buffer, readAmount);
104
* A run is mergable with another if the other a direct successor in the scratch file.
107
public boolean isMergeableWith(REDRun r) {
108
return r.fRider == fRider && r.fOffset == fOffset + fLength;
113
* @see java.lang.Object#toString()
116
public String toString() {
119
} catch (IOException e) {
125
* @see java.lang.CharSequence#charAt(int)
127
public char charAt(int pos) {
129
fRider.seek(fOffset + pos);
130
return fRider.readChar();
131
} catch (IOException e) {
137
* @see java.lang.CharSequence#subSequence(int, int)
139
public CharSequence subSequence(int start, int end) {
140
return new REDRun(fRider, fOffset + start, end - start);
144
* @see java.lang.CharSequence#length()
146
public int length() {