List of usage examples for javax.transaction.xa XAException XAException
public XAException()
From source file:com.clican.pluto.transaction.resources.memory.XAFileResourceMemoryImpl.java
public OutputStream getOutputStream() throws XAException, FileNotFoundException { if (xidThreadLocal.get() == null) { throw new XAException(); }//from w w w.jav a 2 s .c o m OutputStream os = new OutputStream() { @Override public void close() throws IOException { } @Override public void flush() throws IOException { } @Override public void write(byte[] b, int off, int len) throws IOException { if (lockedXid != xidThreadLocal.get()) { throw new IOException( "This file [" + file + "] has been locked by anthoer thread, you can't write it"); } lockedXid = xidThreadLocal.get(); byte[] data = modifiedDataMapping.get(xidThreadLocal.get()); int srcOff = 0; if (data == null) { data = new byte[len]; } else { byte[] old = data; data = new byte[data.length + len]; srcOff = old.length; for (int i = 0; i < old.length; i++) { data[i] = old[i]; } } for (int i = srcOff; i < data.length; i++) { data[i] = b[i - srcOff]; } modifiedDataMapping.put(xidThreadLocal.get(), data); } @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); } @Override public void write(int b) throws IOException { write(new byte[] { (byte) b }); } }; return os; }
From source file:com.clican.pluto.transaction.resources.memory.XAFileSetResourceMemoryImpl.java
public OutputStream getOutputStream(final File file) throws XAException, FileNotFoundException { if (xidThreadLocal.get() == null) { throw new XAException(); }/* www.j a va2 s . c o m*/ OutputStream os = new OutputStream() { @Override public void close() throws IOException { } @Override public void flush() throws IOException { } @Override public void write(byte[] b, int off, int len) throws IOException { if (lockedXid != null && lockedXid != xidThreadLocal.get()) { throw new IOException("This directory [" + directory + "] has been locked by anthoer thread, you can't write it"); } lockedXid = xidThreadLocal.get(); byte[] data = modifiedDataMapping.get(xidThreadLocal.get()).get(file); int srcOff = 0; if (data == null) { data = new byte[len]; } else { byte[] old = data; data = new byte[data.length + len]; srcOff = old.length; for (int i = 0; i < old.length; i++) { data[i] = old[i]; } } for (int i = srcOff; i < data.length; i++) { data[i] = b[i - srcOff]; } modifiedDataMapping.get(xidThreadLocal.get()).put(file, data); } @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); } @Override public void write(int b) throws IOException { write(new byte[] { (byte) b }); } }; return os; }
From source file:com.clican.pluto.transaction.resources.memory.XAFileResourceMemoryImpl.java
public InputStream getInputStream() throws XAException, FileNotFoundException { if (xidThreadLocal.get() == null) { throw new XAException(); }/*from w ww . j av a2 s . c om*/ byte[] data = oldDataMapping.get(xidThreadLocal.get()); if (data == null) { throw new FileNotFoundException(); } return new ByteArrayInputStream(data); }
From source file:com.clican.pluto.transaction.resources.memory.XAFileSetResourceMemoryImpl.java
public InputStream getInputStream(File file) throws XAException, FileNotFoundException { if (xidThreadLocal.get() == null) { throw new XAException(); }// www . j a va 2 s .c o m byte[] data = modifiedDataMapping.get(xidThreadLocal.get()).get(file); if (data == null) { data = oldDataMapping.get(xidThreadLocal.get()).get(file); } if (data == null) { throw new FileNotFoundException(); } return new ByteArrayInputStream(data); }