1
/*******************************************************************************
2
* Copyright (C) 2003-2004, 2013, Guillaume Brocker
4
* All rights reserved. This program and the accompanying materials
5
* are made available under the terms of the Eclipse Public License v1.0
6
* which accompanies this distribution, and is available at
7
* http://www.eclipse.org/legal/epl-v10.html
10
* Guillaume Brocker - Initial API and implementation
12
******************************************************************************/
14
package eclox.core.doxyfiles.io;
16
import java.io.IOException;
17
import java.io.InputStream;
18
import java.util.Iterator;
20
import eclox.core.doxyfiles.Chunk;
21
import eclox.core.doxyfiles.Doxyfile;
24
* Implements a doxyfile content serializer.
28
public class Serializer extends InputStream {
31
* an iterator on the doxyfile chunks
33
private Iterator chunkIterator;
36
* a string buffer containing the next character to red
38
private StringBuffer stringBuffer;
43
* @param doxyfile a doxyfile to serialize
45
public Serializer( Doxyfile doxyfile ) {
46
this.chunkIterator = doxyfile.iterator();
47
this.stringBuffer = getNextStringBuffer();
50
public int read() throws IOException {
52
if( stringBuffer != null ) {
53
// Retrieves the next character from the current string buffer.
54
result = stringBuffer.charAt( 0 );
55
stringBuffer.deleteCharAt( 0 );
57
// If the current string buffer has been entierly read, gets the next string buffer.
58
if( stringBuffer.length() == 0 ) {
59
stringBuffer = getNextStringBuffer();
69
* Retrieves the next string buffer to use for reading operations or null
70
* if no more chunk is left in the doxyfile.
72
* @return a string buffer or null of none
74
private StringBuffer getNextStringBuffer() {
76
assert chunkIterator != null;
78
// Retrieves the next string buffer.
79
StringBuffer result = null;
80
if( this.chunkIterator.hasNext() == true ) {
81
Chunk chunk = (Chunk) this.chunkIterator.next();
82
result = new StringBuffer( chunk.toString() );