~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/disassembly/text/REDRun.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 * 
 
8
 * Contributors:
 
9
 *     Wind River Systems - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.text;
 
12
 
 
13
import java.io.IOException;
 
14
 
 
15
/**
 
16
 * A piece of text on a scratch file.
 
17
 */
 
18
public class REDRun implements CharSequence {
 
19
 
 
20
        IFileRider fRider;
 
21
        int fOffset;
 
22
        int fLength;
 
23
 
 
24
        /**
 
25
         * @pre rider != null
 
26
         * @pre style != null
 
27
         * @pre length > 0
 
28
         */
 
29
        public REDRun(IFileRider rider, int offset, int length) {
 
30
                fRider = rider;
 
31
                fOffset = offset;
 
32
                fLength = length;
 
33
        }
 
34
 
 
35
        /**
 
36
         * @pre rider != null
 
37
         * @pre style != null
 
38
         * @pre str.length() > 0
 
39
         */
 
40
        public REDRun(IFileRider rider, String str) throws IOException {
 
41
                fRider = rider;
 
42
                fLength = str.length();
 
43
                fOffset = fRider.length();
 
44
                fRider.seek(fOffset);
 
45
                fRider.writeChars(str, 0, fLength);
 
46
        }
 
47
 
 
48
        /**
 
49
         * @param rider
 
50
         * @param buf
 
51
         * @param off
 
52
         * @param n
 
53
         */
 
54
        public REDRun(IFileRider rider, char[] buf, int off, int n) throws IOException {
 
55
                fRider = rider;
 
56
                fLength = n;
 
57
                fOffset = fRider.length();
 
58
                fRider.seek(fOffset);
 
59
                fRider.writeChars(buf, off, n);
 
60
        }
 
61
 
 
62
        /**
 
63
         * @post return.length() == length()
 
64
         */
 
65
        public String asString() throws IOException {
 
66
                String retVal;
 
67
                char[] buf = new char[fLength];
 
68
                fRider.seek(fOffset);
 
69
                fRider.readChars(buf);
 
70
                retVal = new String(buf);
 
71
                return retVal;
 
72
        }
 
73
 
 
74
        /**
 
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
 
81
         */
 
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);
 
86
                return readAmount;
 
87
        }
 
88
 
 
89
        /**
 
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
 
95
         */
 
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);
 
100
                return readAmount;
 
101
        }
 
102
 
 
103
        /**
 
104
         * A run is mergable with another if the other a direct successor in the scratch file.
 
105
         * @pre r != null
 
106
         */
 
107
        public boolean isMergeableWith(REDRun r) {
 
108
                return r.fRider == fRider && r.fOffset == fOffset + fLength;
 
109
        }
 
110
 
 
111
        
 
112
        /*
 
113
         * @see java.lang.Object#toString()
 
114
         */
 
115
        @Override
 
116
        public String toString() {
 
117
                try {
 
118
                        return asString();
 
119
                } catch (IOException e) {
 
120
                        return null;
 
121
                }
 
122
        }
 
123
 
 
124
        /*
 
125
         * @see java.lang.CharSequence#charAt(int)
 
126
         */
 
127
        public char charAt(int pos) {
 
128
                try {
 
129
                        fRider.seek(fOffset + pos);
 
130
                        return fRider.readChar();
 
131
                } catch (IOException e) {
 
132
                        return 0;
 
133
                }
 
134
        }
 
135
 
 
136
        /*
 
137
         * @see java.lang.CharSequence#subSequence(int, int)
 
138
         */
 
139
        public CharSequence subSequence(int start, int end) {
 
140
                return new REDRun(fRider, fOffset + start, end - start);
 
141
        }
 
142
 
 
143
        /*
 
144
         * @see java.lang.CharSequence#length()
 
145
         */
 
146
        public int length() {
 
147
                return fLength;
 
148
        }
 
149
}