LibreOffice Module xmerge (master) 1
Record.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge.converter.palm;
20
21import java.io.OutputStream;
22import java.io.InputStream;
23import java.io.DataOutputStream;
24import java.io.DataInputStream;
25import java.io.IOException;
26
35public final class Record {
36
38 private byte[] data;
39
41 private byte attributes = 0;
42
46 public Record() {
47 data = new byte[0];
48 }
49
58 public Record(byte[] d) {
59 this(d, (byte) 0);
60 }
61
72 public Record(byte[] d, byte attrs) {
73 data = new byte[d.length];
74 attributes = attrs;
75 System.arraycopy(d, 0, data, 0, d.length);
76 }
77
83 public int getSize() {
84 return data.length;
85 }
86
92 public byte[] getBytes() {
93 return data;
94 }
95
105 public byte getAttributes() {
106 return attributes;
107 }
108
117 public void write(OutputStream outs) throws IOException {
118 DataOutputStream out = new DataOutputStream(outs);
119 out.writeByte(attributes);
120 out.writeShort(data.length);
121 out.write(data);
122 }
123
132 public void read(InputStream ins) throws IOException {
133 DataInputStream in = new DataInputStream(ins);
134 attributes = in.readByte();
135 int len = in.readUnsignedShort();
136 data = new byte[len];
137 in.readFully(data);
138 }
139
152 @Override
153 public boolean equals(Object obj) {
154 if (!(obj instanceof Record)) {
155 return false;
156 }
157 Record rec = (Record) obj;
158 if (rec.getAttributes() != attributes) {
159 return false;
160 }
161 if (rec.getSize() == data.length) {
162 for (int i = 0; i < data.length; i++) {
163 if (data[i] != rec.data[i]) {
164 return false;
165 }
166 }
167 }
168 return false;
169 }
170
171 @Override
172 public int hashCode() {
173 return 0;
174 }
175
176}
double d
Contains the raw bytes for a Record in a PDB.
Definition: Record.java:35
Record(byte[] d)
Constructor to create a Record filled with bytes.
Definition: Record.java:58
Record(byte[] d, byte attrs)
Constructor to create a Record filled with bytes and assign Record attributes.
Definition: Record.java:72
boolean equals(Object obj)
Override equals method of Object.
Definition: Record.java:153
void write(OutputStream outs)
Write out the Record attributes and Record length followed by the data in this Record object.
Definition: Record.java:117
int getSize()
This method returns the number of bytes in this object.
Definition: Record.java:83
void read(InputStream ins)
Read the necessary data to create a PDB from the InputStream.
Definition: Record.java:132
byte[] getBytes()
This method returns the contents of this Object.
Definition: Record.java:92
unsigned char byte
int i