* <code>ldPathProgram</code>
* @throws LDPathException
*/
public ArchiveInputStream createSchemaArchive(String coreName, String ldPathProgram) throws LDPathException {
ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE);
ArchiveStreamFactory asf = new ArchiveStreamFactory();
TarArchiveOutputStream tarOutputStream = null;
try {
tarOutputStream = (TarArchiveOutputStream) asf.createArchiveOutputStream("tar", out);
} catch (ArchiveException e) {
String msg = "Cannot create an empty tar archive";
logger.error(msg, e);
throw new LDPathException(msg, e);
}
try {
InputStream is = getSolrTemplateStream();
ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
ZipArchiveEntry ze = null;
byte[] schemaFile = null;
while ((ze = zis.getNextZipEntry()) != null) {
if (SOLR_TEMPLATE_SCHEMA.equals(ze.getName())) {
schemaFile = createSchemaXML(getLDPathProgram(ldPathProgram), IOUtils.toByteArray(zis));
TarArchiveEntry te = new TarArchiveEntry(coreName + SOLR_SCHEMA);
te.setSize(schemaFile.length);
tarOutputStream.putArchiveEntry(te);
tarOutputStream.write(schemaFile);
tarOutputStream.closeArchiveEntry();
} else {
TarArchiveEntry te = new TarArchiveEntry(ze.getName().replaceAll(SOLR_TEMPLATE_NAME,
coreName));
te.setSize(ze.getSize());
tarOutputStream.putArchiveEntry(te);
tarOutputStream.write(IOUtils.toByteArray(zis));
tarOutputStream.closeArchiveEntry();
}
}
if (schemaFile == null) {
throw new LDPathException("Schema template ZIP should include: " + SOLR_TEMPLATE_SCHEMA);
}
tarOutputStream.finish();
tarOutputStream.close();
} catch (IOException e) {
logger.error("", e);
throw new LDPathException(e);
}
ArchiveInputStream ret;
try {
ret = asf.createArchiveInputStream(new ByteArrayInputStream(out.toByteArray()));
} catch (ArchiveException e) {
String msg = "Cannot create a final tar archive while creating an ArchiveInputStream to create a Solr core";
logger.error(msg, e);
throw new LDPathException(msg, e);
}