Check-in [49d76c6c68]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Write part of the database fields.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:49d76c6c68444eb34e400c618a4506692d3621f4
User & Date: stephanie.gawroriski 2019-07-13 14:41:23
Context
2019-07-13
14:44
Add write to byte array version of the database. check-in: a2e7a01986 user: stephanie.gawroriski tags: trunk
14:41
Write part of the database fields. check-in: 49d76c6c68 user: stephanie.gawroriski tags: trunk
14:21
Building of the SquirrelJME ROM. check-in: 9edcb5e052 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bldt/libs/palmos-utils/dev/shadowtail/palmos/PalmDatabaseBuilder.java.

7
8
9
10
11
12
13


14
15
16
17
18
19
20
21
22
23
















24
25
26
27
28
29
30
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
..
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
..
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
...
100
101
102
103
104
105
106
107

108
109
110
111
112
113
114
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.palmos;

import java.io.IOException;
import java.io.OutputStream;



/**
 * This class is used to build PalmOS databases and resource databases.
 *
 * @since 2019/07/13
 */
public final class PalmDatabaseBuilder
{
	/** The type of database to create. */
	protected final PalmDatabaseType type;
















	
	/**
	 * Initializes the database builder.
	 *
	 * @param __type The database type.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/13
................................................................................
	 */
	public PalmDatabaseBuilder(PalmDatabaseType __type)
		throws NullPointerException
	{
		if (__type == null)
			throw new NullPointerException("NARG");
		
		this.type = __type;
	}
	
	/**
	 * Adds the specified entry.
	 *
	 * @param __type The entry type.
	 * @param __id The ID to use.
................................................................................
	 */
	public final OutputStream addEntry(String __type, int __id)
		throws NullPointerException
	{
		if (__type == null)
			throw new NullPointerException("NARG");
		
		throw new todo.TODO();

	}
	
	/**
	 * Sets the creator of the database.
	 *
	 * @param __creat The creator to use.
	 * @return {@code this}.
................................................................................
	 */
	public final PalmDatabaseBuilder setCreator(String __creat)
		throws NullPointerException
	{
		if (__creat == null)
			throw new NullPointerException("NARG");
		
		throw new todo.TODO();

	}
	
	/**
	 * Sets the name of the database.
	 *
	 * @param __name The name to use.
	 * @return {@code this}.
................................................................................
	 */
	public final PalmDatabaseBuilder setName(String __name)
		throws NullPointerException
	{
		if (__name == null)
			throw new NullPointerException("NARG");
		
		throw new todo.TODO();

	}
	
	/**
	 * Sets the type of the database.
	 *
	 * @param __type The type to use.
	 * @return {@code this}.
................................................................................
	 */
	public final PalmDatabaseBuilder setType(String __type)
		throws NullPointerException
	{
		if (__type == null)
			throw new NullPointerException("NARG");
		
		throw new todo.TODO();

	}
	
	/**
	 * Writes the database to the output.
	 *
	 * @param __out The output stream.
	 * @throws IOException On write errors.







>
>









|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|
>







 







|
>







 







|
>







 







|
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.palmos;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * This class is used to build PalmOS databases and resource databases.
 *
 * @since 2019/07/13
 */
public final class PalmDatabaseBuilder
{
	/** The type of database to create. */
	protected final PalmDatabaseType dbtype;
	
	/** The entries within the database. */
	private final List<PalmRecord> _records =
		new ArrayList<>();
	
	/** The creator of the database. */
	private String _creator =
		"????";
	
	/** The type of the database. */
	private String _type =
		"????";
	
	/** The name of the database. */
	private String _name =
		"Untitled";
	
	/**
	 * Initializes the database builder.
	 *
	 * @param __type The database type.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/13
................................................................................
	 */
	public PalmDatabaseBuilder(PalmDatabaseType __type)
		throws NullPointerException
	{
		if (__type == null)
			throw new NullPointerException("NARG");
		
		this.dbtype = __type;
	}
	
	/**
	 * Adds the specified entry.
	 *
	 * @param __type The entry type.
	 * @param __id The ID to use.
................................................................................
	 */
	public final OutputStream addEntry(String __type, int __id)
		throws NullPointerException
	{
		if (__type == null)
			throw new NullPointerException("NARG");
		
		// Create a record writer to write there
		return new __RecordWriter__(__type, __id, this._records);
	}
	
	/**
	 * Sets the creator of the database.
	 *
	 * @param __creat The creator to use.
	 * @return {@code this}.
................................................................................
	 */
	public final PalmDatabaseBuilder setCreator(String __creat)
		throws NullPointerException
	{
		if (__creat == null)
			throw new NullPointerException("NARG");
		
		this._creator = __creat;
		return this;
	}
	
	/**
	 * Sets the name of the database.
	 *
	 * @param __name The name to use.
	 * @return {@code this}.
................................................................................
	 */
	public final PalmDatabaseBuilder setName(String __name)
		throws NullPointerException
	{
		if (__name == null)
			throw new NullPointerException("NARG");
		
		this._name = __name;
		return this;
	}
	
	/**
	 * Sets the type of the database.
	 *
	 * @param __type The type to use.
	 * @return {@code this}.
................................................................................
	 */
	public final PalmDatabaseBuilder setType(String __type)
		throws NullPointerException
	{
		if (__type == null)
			throw new NullPointerException("NARG");
		
		this._type = __type;
		return this;
	}
	
	/**
	 * Writes the database to the output.
	 *
	 * @param __out The output stream.
	 * @throws IOException On write errors.

Changes to bldt/libs/palmos-utils/dev/shadowtail/palmos/PalmRecord.java.

6
7
8
9
10
11
12
13
14
15
16
17
18


19


20






































// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.palmos;

/**
 * DESCRIBE THIS.
 *
 * @since 2019/07/13
 */
public class PalmRecord
{


}
















































|



|

>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.palmos;

/**
 * This represents a single record within a database.
 *
 * @since 2019/07/13
 */
public final class PalmRecord
{
	/** The type. */
	public final String type;
	
	/** The record ID. */
	public final int id;
	
	/** The record length. */
	public final int length;
	
	/** The data. */
	final byte[] _data;
	
	/**
	 * Initializes the Palm record.
	 *
	 * @param __type The type.
	 * @param __id The ID.
	 * @param __b The buffer.
	 * @param __o The offset.
	 * @param __l The length.
	 * @throws IndexOutOfBoundsException If the offset and/or length are
	 * negative or exceed the array bounds.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/13
	 */
	public PalmRecord(String __type, int __id, byte[] __b, int __o, int __l)
		throws IndexOutOfBoundsException, NullPointerException
	{
		if (__type == null || __b == null)
			throw new NullPointerException("NARG");
		if (__o < 0 || __l < 0 || (__o + __l) > __b.length)
			throw new IndexOutOfBoundsException("IOOB");
		
		this.type = __type;
		this.id = __id;
		this.length = __l;
		
		// Copy and store bytes
		byte[] dest = new byte[__l];
		System.arraycopy(__b, __o, dest, 0, __l);
		this._data = dest;
	}
}

Added bldt/libs/palmos-utils/dev/shadowtail/palmos/__RecordWriter__.java.



































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.palmos;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;

/**
 * This is used to write to the record data.
 *
 * @since 2019/07/13
 */
final class __RecordWriter__
	extends OutputStream
{
	/** The type used. */
	protected final String type;
	
	/** The ID used. */
	protected final int id;
	
	/** The record data. */
	private final ByteArrayOutputStream _data =
		new ByteArrayOutputStream();
	
	/** The target record collection. */
	private final Collection<PalmRecord> _target;
	
	/** Has this been closed? */
	private volatile boolean _closed;
	
	/**
	 * Initializes the record writer.
	 *
	 * @param __type The record type.
	 * @param __id The record ID.
	 * @param __t The target type.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/13
	 */
	__RecordWriter__(String __type, int __id, Collection<PalmRecord> __t)
		throws NullPointerException
	{
		if (__type == null || __t == null)
			throw new NullPointerException("NARG");
		
		this.type = __type;
		this.id = __id;
		this._target = __t;
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/07/13
	 */
	@Override
	public final void close()
	{
		// Only close once
		if (this._closed)
			return;
		
		// Set as closed
		this._closed = true;
		
		// Add record information
		byte[] buf = this._data.toByteArray();
		this._target.add(new PalmRecord(this.type, this.id,
			buf, 0, buf.length));
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/07/13
	 */
	@Override
	public final void write(int __b)
		throws IOException
	{
		// Do not write when closed
		if (this._closed)
			throw new IOException("EOFF");
		
		// Forward
		this._data.write(__b);
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/07/13
	 */
	@Override
	public final void write(byte[] __b)
		throws IOException
	{
		// Do not write when closed
		if (this._closed)
			throw new IOException("EOFF");
			
		// Forward
		this._data.write(__b);
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/07/13
	 */
	@Override
	public final void write(byte[] __b, int __o, int __l)
		throws IOException
	{
		// Do not write when closed
		if (this._closed)
			throw new IOException("EOFF");
			
		// Forward
		this._data.write(__b, __o, __l);
	}
}