use of org.apache.commons.io.IOExceptionWithCause in project opennms by OpenNMS.
the class VmwareRequisitionUrlConnection method getInputStream.
/**
* {@inheritDoc}
* <p/>
* Creates a ByteArrayInputStream implementation of InputStream of the XML
* marshaled version of the Requisition class. Calling close on this stream
* is safe.
*/
@Override
public InputStream getInputStream() throws IOException {
InputStream stream = null;
try {
final Requisition existingRequisition = getExistingRequisition(importRequest.getForeignSource());
importRequest.setExistingRequisition(existingRequisition);
final VmwareImporter importer = new VmwareImporter(importRequest);
stream = new ByteArrayInputStream(jaxBMarshal(importer.getRequisition()).getBytes());
} catch (Throwable e) {
logger.warn("Problem getting input stream: '{}'", e);
throw new IOExceptionWithCause("Problem getting input stream: " + e, e);
}
return stream;
}
use of org.apache.commons.io.IOExceptionWithCause in project hive by apache.
the class ReplicationUtils method deserializeCommand.
/**
* Command implements Writable, but that's not terribly easy to use compared
* to String, even if it plugs in easily into the rest of Hadoop. Provide
* utility methods to easily serialize and deserialize Commands
*
* deserializeCommand instantiates a concrete Command and initializes it,
* given a base64 String representation of it.
*/
public static Command deserializeCommand(String s) throws IOException {
DataInput dataInput = new DataInputStream(new ByteArrayInputStream(Base64.decodeBase64(s)));
String clazz = (String) ReaderWriter.readDatum(dataInput);
Command cmd;
try {
cmd = (Command) Class.forName(clazz).newInstance();
} catch (Exception e) {
throw new IOExceptionWithCause("Error instantiating class " + clazz, e);
}
cmd.readFields(dataInput);
return cmd;
}
use of org.apache.commons.io.IOExceptionWithCause in project jackrabbit by apache.
the class BundleReader method readPropertyEntry.
/**
* Deserializes a <code>PropertyState</code> from the data input stream.
*
* @param id the property id for the new property entry
* @return the property entry
* @throws IOException if an I/O error occurs.
*/
private NodePropBundle.PropertyEntry readPropertyEntry(PropertyId id) throws IOException {
NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id);
int count = 1;
if (version >= BundleBinding.VERSION_3) {
int b = in.readUnsignedByte();
entry.setType(b & 0x0f);
int len = b >>> 4;
if (len != 0) {
entry.setMultiValued(true);
if (len == 0x0f) {
count = readVarInt() + 0x0f - 1;
} else {
count = len - 1;
}
}
entry.setModCount((short) readVarInt());
} else {
// type and modcount
int type = in.readInt();
entry.setModCount((short) ((type >> 16) & 0x0ffff));
type &= 0x0ffff;
entry.setType(type);
// multiValued
entry.setMultiValued(in.readBoolean());
// definitionId
in.readUTF();
// count
count = in.readInt();
}
// values
InternalValue[] values = new InternalValue[count];
String[] blobIds = new String[count];
for (int i = 0; i < count; i++) {
InternalValue val;
int type = entry.getType();
switch(type) {
case PropertyType.BINARY:
int size = in.readInt();
if (size == BundleBinding.BINARY_IN_DATA_STORE) {
val = InternalValue.create(binding.dataStore, readString());
} else if (size == BundleBinding.BINARY_IN_BLOB_STORE) {
blobIds[i] = readString();
try {
BLOBStore blobStore = binding.getBlobStore();
if (blobStore instanceof ResourceBasedBLOBStore) {
val = InternalValue.create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i]));
} else {
val = InternalValue.create(blobStore.get(blobIds[i]));
}
} catch (IOException e) {
if (binding.errorHandling.ignoreMissingBlobs()) {
log.warn("Ignoring error while reading blob-resource: " + e);
val = InternalValue.create(new byte[0]);
} else {
throw e;
}
} catch (Exception e) {
throw new IOExceptionWithCause("Unable to create property value: " + e.toString(), e);
}
} else {
// short values into memory
byte[] data = new byte[size];
in.readFully(data);
val = InternalValue.create(data);
}
break;
case PropertyType.DOUBLE:
val = InternalValue.create(in.readDouble());
break;
case PropertyType.DECIMAL:
val = InternalValue.create(readDecimal());
break;
case PropertyType.LONG:
if (version >= BundleBinding.VERSION_3) {
val = InternalValue.create(readVarLong());
} else {
val = InternalValue.create(in.readLong());
}
break;
case PropertyType.BOOLEAN:
val = InternalValue.create(in.readBoolean());
break;
case PropertyType.NAME:
val = InternalValue.create(readQName());
break;
case PropertyType.WEAKREFERENCE:
val = InternalValue.create(readNodeId(), true);
break;
case PropertyType.REFERENCE:
val = InternalValue.create(readNodeId(), false);
break;
case PropertyType.DATE:
if (version >= BundleBinding.VERSION_3) {
val = InternalValue.create(readDate());
break;
}
// else fall through
default:
if (version >= BundleBinding.VERSION_3) {
val = InternalValue.valueOf(readString(), entry.getType());
} else {
// because writeUTF(String) has a size limit of 64k,
// Strings are serialized as <length><byte[]>
int len = in.readInt();
byte[] bytes = new byte[len];
in.readFully(bytes);
String stringVal = new String(bytes, "UTF-8");
// https://issues.apache.org/jira/browse/JCR-3083
if (PropertyType.DATE == entry.getType()) {
val = InternalValue.createDate(stringVal);
} else {
val = InternalValue.valueOf(stringVal, entry.getType());
}
}
}
values[i] = val;
}
entry.setValues(values);
entry.setBlobIds(blobIds);
return entry;
}
use of org.apache.commons.io.IOExceptionWithCause in project jackrabbit by apache.
the class BundleWriter method writeSmallBinary.
/**
* Write a small binary value and return the data.
*
* @param value the binary value
* @param state the property state (for error messages)
* @param i the index (for error messages)
* @return the data
* @throws IOException if the data could not be read
*/
private byte[] writeSmallBinary(InternalValue value, NodePropBundle.PropertyEntry state, int i) throws IOException {
try {
int size = (int) value.getLength();
out.writeInt(size);
byte[] data = new byte[size];
DataInputStream in = new DataInputStream(value.getStream());
try {
in.readFully(data);
} finally {
IOUtils.closeQuietly(in);
}
out.write(data, 0, data.length);
return data;
} catch (Exception e) {
String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " value=" + value;
log.error(msg, e);
throw new IOExceptionWithCause(msg, e);
}
}
use of org.apache.commons.io.IOExceptionWithCause in project tika by apache.
the class AbstractDBParser method getConnection.
/**
* Override this for special configuration of the connection, such as limiting
* the number of rows to be held in memory.
*
* @param stream stream to use
* @param metadata metadata that could be used in parameterizing the connection
* @param context parsecontext that could be used in parameterizing the connection
* @return connection
* @throws java.io.IOException
* @throws org.apache.tika.exception.TikaException
*/
protected Connection getConnection(InputStream stream, Metadata metadata, ParseContext context) throws IOException, TikaException {
String connectionString = getConnectionString(stream, metadata, context);
Connection connection = null;
try {
Class.forName(getJDBCClassName());
} catch (ClassNotFoundException e) {
throw new TikaException(e.getMessage());
}
try {
connection = DriverManager.getConnection(connectionString);
} catch (SQLException e) {
throw new IOExceptionWithCause(e);
}
return connection;
}
Aggregations