use of com.swiftmq.tools.util.DataStreamInputStream in project swiftmq-client by iitsoftware.
the class AMQPMessage method decode.
private void decode() throws Exception {
DataInput dataInput = null;
if (multiBody != null) {
dataInput = new DataStreamInputStream(new MultiByteArrayInputStream(multiBody, totalSize));
bodySize = totalSize;
} else {
dataInput = new DataByteArrayInputStream(body);
bodySize = body.length;
}
parseSections(dataInput);
}
use of com.swiftmq.tools.util.DataStreamInputStream in project swiftmq-ce by iitsoftware.
the class Importer method execute.
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length < 3)
return new String[] { TreeCommands.ERROR, "Invalid command, please try '" + TreeCommands.IMPORT + " <localdir> <queuename> [-newheader] [-delete] [-filter <regex>]" };
int nMsgs = 0;
try {
String localDir = cmd[1];
String queueName = cmd[2];
boolean delete = false;
boolean newId = false;
String filter = null;
if (cmd.length > 3) {
StringBuffer selBuffer = null;
for (int i = 3; i < cmd.length; i++) {
if (selBuffer != null)
selBuffer.append(cmd[i]);
else if (cmd[i].equals("-delete"))
delete = true;
else if (cmd[i].equals("-newid"))
newId = true;
else if (cmd[i].equals("-filter"))
selBuffer = new StringBuffer();
else
throw new Exception("Invalid option: " + cmd[i]);
}
if (selBuffer != null)
filter = selBuffer.toString();
}
String idPrefix = null;
if (newId) {
StringBuffer b = new StringBuffer(SwiftletManager.getInstance().getRouterName());
b.append('/');
b.append(IdGenerator.getInstance().nextId('/'));
b.append('/');
idPrefix = b.toString();
}
XStream xStream = null;
File inputDir = new File(localDir);
if (!inputDir.exists())
throw new Exception("Input directory doesn't exists: " + localDir);
xStream = new XStream(new Dom4JDriver());
xStream.allowTypesByWildcard(new String[] { ".*" });
QueueSender sender = ctx.queueManager.createQueueSender(queueName, null);
try {
MessageImpl msg = null;
File[] files = null;
files = inputDir.listFiles(new RegexFilter(filter) {
public boolean accept(File file, String s) {
return regex == null || s.matches(regex);
}
});
if (files != null && files.length > 0) {
Arrays.sort(files);
for (int i = 0; i < files.length; i++) {
msg = null;
if (!files[i].isDirectory()) {
if (files[i].getName().endsWith(".xml")) {
BufferedReader bufferedReader = new BufferedReader(new FileReader(files[i]));
msg = (MessageImpl) xStream.fromXML(bufferedReader);
bufferedReader.close();
} else if (files[i].getName().endsWith(".message")) {
DataStreamInputStream dis = new DataStreamInputStream(new BufferedInputStream(new FileInputStream(files[i])));
msg = MessageImpl.createInstance(dis.readInt());
msg.readContent(dis);
dis.close();
}
if (msg != null) {
if (newId) {
StringBuffer b = new StringBuffer(idPrefix);
b.append(nMsgs);
msg.setJMSMessageID(b.toString());
}
QueuePushTransaction pushTx = sender.createTransaction();
pushTx.putMessage(msg);
pushTx.commit();
if (delete)
files[i].delete();
nMsgs++;
}
}
}
}
} finally {
try {
sender.close();
} catch (Exception e) {
}
}
} catch (Exception e) {
return new String[] { TreeCommands.ERROR, e.getMessage() };
}
return new String[] { TreeCommands.INFO, nMsgs + " messages imported." };
}
Aggregations