Skip to main content
summaryrefslogtreecommitdiffstats
blob: e081ade5c4887d362d5650f372703100bcd5df7c (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2001, 2010 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.test.util;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;



/**
 * Represents a piece of java code (usually a full compilation unit) that is loaded
 * from a static test file somewhere.  
 * 
 * @author cbateman
 *
 */
public class TestFileResource extends LoadableResource
{
    private ByteArrayOutputStream   _buffer = new ByteArrayOutputStream();
    
    /**
     * @return the contents
     */
    public String toString()
    {
        return _buffer.toString();
    }

    public String toString(final String encoding) throws UnsupportedEncodingException
    {
        return _buffer.toString(encoding);

    }
    /**
     * @return the contents as a byte array
     */
    public byte[] toBytes()
    {
        return _buffer.toByteArray();
    }
    
    protected void bufferLoaded(byte[] buffer, int numBytes) 
    {
        _buffer.write(buffer, 0, numBytes);
    }
}

Back to the top