com.sun.xml.ws.encoding.fastinfoset.FastInfosetStreamReaderFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webservices-rt Show documentation
Show all versions of webservices-rt Show documentation
This module contains the Metro runtime code.
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.ws.encoding.fastinfoset;
import com.sun.xml.fastinfoset.stax.StAXDocumentParser;
import com.sun.xml.ws.api.streaming.XMLStreamReaderFactory;
import java.io.InputStream;
import java.io.Reader;
import javax.xml.stream.XMLStreamReader;
/**
* @author Alexey Stashok
*/
public final class FastInfosetStreamReaderFactory extends XMLStreamReaderFactory {
private static final FastInfosetStreamReaderFactory factory = new FastInfosetStreamReaderFactory();
private ThreadLocal pool = new ThreadLocal();
public static FastInfosetStreamReaderFactory getInstance() {
return factory;
}
public XMLStreamReader doCreate(String systemId, InputStream in, boolean rejectDTDs) {
StAXDocumentParser parser = fetch();
if (parser == null) {
return FastInfosetCodec.createNewStreamReaderRecyclable(in, false);
}
parser.setInputStream(in);
return parser;
}
public XMLStreamReader doCreate(String systemId, Reader reader, boolean rejectDTDs) {
throw new UnsupportedOperationException();
}
private StAXDocumentParser fetch() {
StAXDocumentParser parser = pool.get();
pool.set(null);
return parser;
}
public void doRecycle(XMLStreamReader r) {
if (r instanceof StAXDocumentParser) {
pool.set((StAXDocumentParser) r);
}
}
}