// Path: src/main/java/com/marcospassos/phpserializer/state/FinishedState.java
// public class FinishedState extends AbstractState
// {
//     @Override
//     public boolean isReferable()
//     {
//         return false;
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingValueState.java
// public class WritingValueState extends AbstractState
// {
//     /**
//      * The parent state.
//      */
//     WriterState parent;
// 
//     /**
//      * Creates an initial state.
//      */
//     public WritingValueState()
//     {
//         this(new FinishedState());
//     }
// 
//     /**
//      * Creates a new state from the specified parent state.
//      *
//      * @param parent The parent state.
//      */
//     public WritingValueState(WriterState parent)
//     {
//         this.parent = parent;
//     }
// 
//     @Override
//     public boolean isReferable()
//     {
//         return true;
//     }
// 
//     @Override
//     public WriterState serializableBegin()
//     {
//         return new WritingSerializableObjectState(parent);
//     }
// 
//     @Override
//     public WriterState objectBegin()
//     {
//         return new WritingObjectState(parent);
//     }
// 
//     @Override
//     public WriterState value()
//     {
//         return parent;
//     }
// 
//     @Override
//     public WriterState arrayBegin()
//     {
//         return new WritingArrayState(parent);
//     }
// }


import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import com.marcospassos.phpserializer.state.FinishedState;
import com.marcospassos.phpserializer.state.WritingValueState;

package com.marcospassos.phpserializer;


/**
 * Writes a values in PHP's serialization format.
 *
 * @author Marcos Passos
 * @since 1.0
 */
public class Writer
{
    /**
     * The buffer that stores the data.
     */
    private StringBuffer buffer;

    /**
     * The reference counter.
     */
    private int pointer = 1;

    /**
     * The current state of the writer.
     */
    private WriterState state;

    /**
     * The current sub writer.
     */
    private Writer subWriter;

    /**
     * Creates a new writer using an internal buffer.
     */
    public Writer()
    {
        this(new StringBuffer());
    }

    /**
     * Creates a writer specifying a buffer to write the data to.
     *
     * @param buffer The buffer to write the data to.
     */
    public Writer(StringBuffer buffer)
    {
        this.buffer = buffer;
// Path: src/main/java/com/marcospassos/phpserializer/state/FinishedState.java
// public class FinishedState extends AbstractState
// {
//     @Override
//     public boolean isReferable()
//     {
//         return false;
//     }
// }
// 
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingValueState.java
// public class WritingValueState extends AbstractState
// {
//     /**
//      * The parent state.
//      */
//     WriterState parent;
// 
//     /**
//      * Creates an initial state.
//      */
//     public WritingValueState()
//     {
//         this(new FinishedState());
//     }
// 
//     /**
//      * Creates a new state from the specified parent state.
//      *
//      * @param parent The parent state.
//      */
//     public WritingValueState(WriterState parent)
//     {
//         this.parent = parent;
//     }
// 
//     @Override
//     public boolean isReferable()
//     {
//         return true;
//     }
// 
//     @Override
//     public WriterState serializableBegin()
//     {
//         return new WritingSerializableObjectState(parent);
//     }
// 
//     @Override
//     public WriterState objectBegin()
//     {
//         return new WritingObjectState(parent);
//     }
// 
//     @Override
//     public WriterState value()
//     {
//         return parent;
//     }
// 
//     @Override
//     public WriterState arrayBegin()
//     {
//         return new WritingArrayState(parent);
//     }
// }


// Path: src/main/java/com/marcospassos/phpserializer/Writer.java
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import com.marcospassos.phpserializer.state.FinishedState;
import com.marcospassos.phpserializer.state.WritingValueState;


package com.marcospassos.phpserializer;


/**
 * Writes a values in PHP's serialization format.
 *
 * @author Marcos Passos
 * @since 1.0
 */
public class Writer
{
    /**
     * The buffer that stores the data.
     */
    private StringBuffer buffer;

    /**
     * The reference counter.
     */
    private int pointer = 1;

    /**
     * The current state of the writer.
     */
    private WriterState state;

    /**
     * The current sub writer.
     */
    private Writer subWriter;

    /**
     * Creates a new writer using an internal buffer.
     */
    public Writer()
    {
        this(new StringBuffer());
    }

    /**
     * Creates a writer specifying a buffer to write the data to.
     *
     * @param buffer The buffer to write the data to.
     */
    public Writer(StringBuffer buffer)
    {
        this.buffer = buffer;
        this.state = new WritingValueState();