KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > BinaryLine


1 /*
2  * BinaryLine.java
3  *
4  * Copyright (C) 1999-2002 Peter Graves
5  * $Id: BinaryLine.java,v 1.1.1.1 2002/09/24 16:09:11 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 {
26     private final int start;
27     private final byte[] bytes;
28     private final int count;
29
30     public BinaryLine(int start, byte[] bytes, int count)
31     {
32          this.start = start;
33          this.bytes = bytes;
34          this.count = count;
35     }
36
37     public final int flags()
38     {
39         return 0;
40     }
41
42     public final void setFlags(int flags) {}
43
44     public final String JavaDoc getText()
45     {
46         Debug.assertTrue(bytes != null);
47         FastStringBuffer sb = new FastStringBuffer(256);
48         String JavaDoc s = Long.toHexString(0x100000000L + start);
49         s = s.substring(1, s.length());
50         sb.append(s + " ");
51         int end = start + count;
52         for (int i = start; i < end; i++) {
53             s = Integer.toHexString(0x200 + bytes[i]);
54             s = s.substring(1, s.length()) + " ";
55             sb.append(s);
56         }
57         // Pad short lines.
58
for (int i = count; i < 16; i++)
59             sb.append(" ");
60         for (int i = start; i < end; i++) {
61             char c = (char) bytes[i];
62             if (c < ' ' || c >= 0x7f)
63                 c = '.';
64             sb.append(c);
65         }
66         return sb.toString();
67     }
68
69     public final void setText(String JavaDoc s) {}
70
71     public final char charAt(int i)
72     {
73         return getText().charAt(i);
74     }
75
76     public final String JavaDoc substring(int beginIndex)
77     {
78         return getText().substring(beginIndex);
79     }
80
81     public final String JavaDoc substring(int beginIndex, int endIndex)
82     {
83         return getText().substring(beginIndex, endIndex);
84     }
85
86     public final String JavaDoc trim()
87     {
88         return getText().trim();
89     }
90
91     public final int length()
92     {
93         return getText().length();
94     }
95
96     public final byte[] getBytes(String JavaDoc encoding)
97     {
98         return bytes;
99     }
100
101     public final boolean isBlank()
102     {
103         return false;
104     }
105 }
106
Popular Tags