OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [java/] [nio/] [CharSequenceBuffer.java] - Blame information for rev 771

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 771 jeremybenn
/* CharBuffer.java --
2
   Copyright (C) 2007  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package java.nio;
40
 
41
/**
42
 * A CharBuffer that wraps a {@link CharSequence}.
43
 */
44
final class CharSequenceBuffer
45
  extends CharBuffer
46
{
47
 
48
  /**
49
   * The wrapped char sequence.
50
   */
51
  private final CharSequence charSequence;
52
 
53
  /**
54
   * Creates a new CharSequenceBuffer.
55
   *
56
   * @param charSeq the CharSequence to wrap
57
   * @param capacity the capacity
58
   * @param limit the limit
59
   * @param position the position
60
   * @param mark the mark
61
   * @param offs the offset
62
   */
63
  CharSequenceBuffer(CharSequence charSeq, int capacity, int limit,
64
                     int position, int mark, int offs)
65
  {
66
    super(capacity, limit, position, mark, null, null, offs);
67
    this.charSequence = charSeq;
68
  }
69
 
70
  /**
71
   * Creates a new instance of CharSequenceBuffer, wrapping the specified
72
   * {@link CharSequence}.
73
   *
74
   * @param charSeq the char sequence to wrap
75
   * @param start the start index in the char sequence
76
   * @param end the end index in the char sequence
77
   */
78
  CharSequenceBuffer(CharSequence charSeq, int start, int end)
79
  {
80
    this(charSeq, charSeq.length(), end, start, -1, 0);
81
  }
82
 
83
  /**
84
   * Returns a read-only view of this buffer.
85
   */
86
  public CharBuffer asReadOnlyBuffer()
87
  {
88
    return duplicate();
89
  }
90
 
91
  /**
92
   * This buffer class is not writable by definition and thus throws
93
   * a ReadOnlyBufferException here.
94
   */
95
  public CharBuffer compact()
96
  {
97
    throw new ReadOnlyBufferException();
98
  }
99
 
100
  /**
101
   * Returns a duplicate of this buffer.
102
   *
103
   * @return a duplicate of this buffer
104
   */
105
  public CharBuffer duplicate()
106
  {
107
    return new CharSequenceBuffer(charSequence, capacity(), limit, pos, mark, 0);
108
  }
109
 
110
  /**
111
   * Returns the character at the current position.
112
   *
113
   * @return the character at the current position
114
   */
115
  public char get()
116
  {
117
    if (pos >= limit)
118
      throw new BufferUnderflowException();
119
 
120
    return charSequence.charAt(array_offset + pos++);
121
  }
122
 
123
  /**
124
   * Returns the character at the specified position.
125
   *
126
   * @return the character at the specified position
127
   */
128
  public char get(int index)
129
  {
130
    if (index < 0 || index >= limit)
131
      throw new IndexOutOfBoundsException();
132
 
133
    return charSequence.charAt(array_offset + index);
134
  }
135
 
136
  /**
137
   * Cannot be direct, return <code>false</code> here.
138
   *
139
   * @return false
140
   */
141
  public boolean isDirect()
142
  {
143
    return false;
144
  }
145
 
146
  /**
147
   * Returns the byte order of this buffer. This is always the native byte
148
   * order.
149
   *
150
   * @return the byte order of this buffer
151
   */
152
  public ByteOrder order()
153
  {
154
    return ByteOrder.nativeOrder();
155
  }
156
 
157
  /**
158
   * This buffer class is not writable by definition and thus throws
159
   * a ReadOnlyBufferException here.
160
   */
161
  public CharBuffer put(char b)
162
  {
163
    throw new ReadOnlyBufferException();
164
  }
165
 
166
  /**
167
   * This buffer class is not writable by definition and thus throws
168
   * a ReadOnlyBufferException here.
169
   */
170
  public CharBuffer put(int index, char b)
171
  {
172
    throw new ReadOnlyBufferException();
173
  }
174
 
175
  /**
176
   * Returns a slice of this buffer, exposing the current position and limit.
177
   */
178
  public CharBuffer slice()
179
  {
180
    int newCapacity = limit - pos;
181
    return new CharSequenceBuffer(charSequence, newCapacity, newCapacity, 0,
182
                                  -1, pos);
183
  }
184
 
185
  /**
186
   * Returns a sub sequence from the specified start index and with the
187
   * specified length.
188
   *
189
   * @param start the start index
190
   * @param length the length of the sub sequence
191
   */
192
  public CharSequence subSequence(int start, int length)
193
  {
194
    int begin = array_offset + start + pos;
195
    return charSequence.subSequence(begin, begin + length);
196
  }
197
 
198
  /**
199
   * This kind of CharBuffer is read-only, so we return <code>true</code>
200
   * here.
201
   */
202
  public boolean isReadOnly()
203
  {
204
    return true;
205
  }
206
 
207
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.