context);
try {
final URLConfiguration urlConfiguration =
URLConfigurationFactory.getURLConfiguration(url, context);
URLContent content =
manager.getURLContent(url, timeout, urlConfiguration);
// The encoding to use is determined as follows.
//
// 1) The document being included specifies an encoding in
// the header, otherwise
// 2) the value of the encoding attribute if one extist,
// otherwise
// 3) UTF-8
// try to obtain the encoding using approach 1.
characterEncoding = content.getCharacterEncoding();
// try to obtain the encoding using approach 2.
if (null == characterEncoding) {
characterEncoding = encoding;
}
// try to obtain the encoding using approach 3.
if (null == characterEncoding) {
characterEncoding = DEFAULT_TEXT_ENCODING;
}
InputStream is =
new BufferedInputStream(content.getInputStream());
InputStreamReader reader =
new InputStreamReader(is, characterEncoding);
final int CHUNK_SIZE = 1024;
final char[] chars = new char[CHUNK_SIZE];
int charsRead = 0;
while (-1 != charsRead) {
// read a chunk of the text into the buffer
charsRead = reader.read(chars, 0, CHUNK_SIZE);
if (charsRead > 0) {
// pass the characters down the XML pipeline
target.characters(chars, 0, charsRead);
}
}
// add dependency to the dependency context
final DependencyContext dependencyContext =
context.getDependencyContext();
if (dependencyContext != null &&
dependencyContext.isTrackingDependencies()) {
dependencyContext.addDependency(content.getDependency());
}
} catch (UnsupportedEncodingException uee) {
// get hold of the current locator
Locator currentLocator =
context.getCurrentLocator();