~ubuntu-branches/ubuntu/utopic/eclipse-eclox/utopic

« back to all changes in this revision

Viewing changes to eclox.core/src/eclox/core/doxyfiles/io/Serializer.java

  • Committer: Package Import Robot
  • Author(s): Graham Inggs
  • Date: 2013-07-07 20:33:10 UTC
  • Revision ID: package-import@ubuntu.com-20130707203310-a44yw80gqtc2s9ob
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (C) 2003-2004, 2013, Guillaume Brocker
 
3
 * 
 
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
 
8
 *
 
9
 * Contributors:
 
10
 *     Guillaume Brocker - Initial API and implementation
 
11
 *
 
12
 ******************************************************************************/ 
 
13
 
 
14
package eclox.core.doxyfiles.io;
 
15
 
 
16
import java.io.IOException;
 
17
import java.io.InputStream;
 
18
import java.util.Iterator;
 
19
 
 
20
import eclox.core.doxyfiles.Chunk;
 
21
import eclox.core.doxyfiles.Doxyfile;
 
22
 
 
23
/**
 
24
 * Implements a doxyfile content serializer.
 
25
 * 
 
26
 * @author willy
 
27
 */
 
28
public class Serializer extends InputStream {
 
29
        
 
30
        /**
 
31
         * an iterator on the doxyfile chunks
 
32
         */
 
33
        private Iterator chunkIterator;
 
34
        
 
35
        /**
 
36
         * a string buffer containing the next character to red
 
37
         */
 
38
        private StringBuffer stringBuffer;
 
39
        
 
40
        /**
 
41
         * Constructor
 
42
         * 
 
43
         * @param       doxyfile        a doxyfile to serialize
 
44
         */
 
45
        public Serializer( Doxyfile doxyfile ) {
 
46
                this.chunkIterator = doxyfile.iterator();
 
47
                this.stringBuffer = getNextStringBuffer();
 
48
        }
 
49
 
 
50
        public int read() throws IOException {
 
51
                int     result;
 
52
                if( stringBuffer != null ) {
 
53
                        // Retrieves the next character from the current string buffer.
 
54
                        result = stringBuffer.charAt( 0 );
 
55
                        stringBuffer.deleteCharAt( 0 );
 
56
                        
 
57
                        // If the current string buffer has been entierly read, gets the next string buffer.
 
58
                        if( stringBuffer.length() == 0 ) {
 
59
                                stringBuffer = getNextStringBuffer();
 
60
                        }
 
61
                }
 
62
                else {
 
63
                        result = -1;
 
64
                }
 
65
                return result;
 
66
        }
 
67
        
 
68
        /**
 
69
         * Retrieves the next string buffer to use for reading operations or null
 
70
         * if no more chunk is left in the doxyfile.
 
71
         * 
 
72
         * @return      a string buffer or null of none
 
73
         */
 
74
        private StringBuffer getNextStringBuffer() {
 
75
        // Pre-condition
 
76
        assert chunkIterator != null;
 
77
        
 
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() );
 
83
                }
 
84
                return result;
 
85
        }
 
86
 
 
87
}