01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.util;
17:
18: import org.springframework.core.io.AbstractResource;
19:
20: import java.io.ByteArrayInputStream;
21: import java.io.IOException;
22: import java.io.InputStream;
23:
24: /**
25: * An in memory implementation of Spring's {@link org.springframework.core.io.Resource} interface.
26: * <p>Used by the "Acegifier" web application to create a bean factory from an XML string, rather than a file.</p>
27: *
28: * @author Luke Taylor
29: * @version $Id: InMemoryResource.java 1784 2007-02-24 21:00:24Z luke_t $
30: */
31: public class InMemoryResource extends AbstractResource {
32: //~ Instance fields ================================================================================================
33:
34: private ByteArrayInputStream in;
35: private String description;
36:
37: //~ Constructors ===================================================================================================
38:
39: public InMemoryResource(byte[] source) {
40: this (source, null);
41: }
42:
43: public InMemoryResource(byte[] source, String description) {
44: in = new ByteArrayInputStream(source);
45: this .description = description;
46: }
47:
48: //~ Methods ========================================================================================================
49:
50: public String getDescription() {
51: return (description == null) ? in.toString() : description;
52: }
53:
54: public InputStream getInputStream() throws IOException {
55: return in;
56: }
57: }
|