01: /*
02: * BinaryLine.java
03: *
04: * Copyright (C) 1999-2002 Peter Graves
05: * $Id: BinaryLine.java,v 1.1.1.1 2002/09/24 16:09:11 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: public final class BinaryLine extends AbstractLine implements Line {
25: private final int start;
26: private final byte[] bytes;
27: private final int count;
28:
29: public BinaryLine(int start, byte[] bytes, int count) {
30: this .start = start;
31: this .bytes = bytes;
32: this .count = count;
33: }
34:
35: public final int flags() {
36: return 0;
37: }
38:
39: public final void setFlags(int flags) {
40: }
41:
42: public final String getText() {
43: Debug.assertTrue(bytes != null);
44: FastStringBuffer sb = new FastStringBuffer(256);
45: String s = Long.toHexString(0x100000000L + start);
46: s = s.substring(1, s.length());
47: sb.append(s + " ");
48: int end = start + count;
49: for (int i = start; i < end; i++) {
50: s = Integer.toHexString(0x200 + bytes[i]);
51: s = s.substring(1, s.length()) + " ";
52: sb.append(s);
53: }
54: // Pad short lines.
55: for (int i = count; i < 16; i++)
56: sb.append(" ");
57: for (int i = start; i < end; i++) {
58: char c = (char) bytes[i];
59: if (c < ' ' || c >= 0x7f)
60: c = '.';
61: sb.append(c);
62: }
63: return sb.toString();
64: }
65:
66: public final void setText(String s) {
67: }
68:
69: public final char charAt(int i) {
70: return getText().charAt(i);
71: }
72:
73: public final String substring(int beginIndex) {
74: return getText().substring(beginIndex);
75: }
76:
77: public final String substring(int beginIndex, int endIndex) {
78: return getText().substring(beginIndex, endIndex);
79: }
80:
81: public final String trim() {
82: return getText().trim();
83: }
84:
85: public final int length() {
86: return getText().length();
87: }
88:
89: public final byte[] getBytes(String encoding) {
90: return bytes;
91: }
92:
93: public final boolean isBlank() {
94: return false;
95: }
96: }
|