protected void eq(Buf buf, String expected) { eq(buf.size(), expected.getBytes().length); eq(buf.data(), expected); byte[] bbytes = new byte[buf.size()]; ByteBuffer bufy = ByteBuffer.wrap(bbytes); buf.writeTo(bufy); eq(new String(bbytes), expected); int size = (int) Math.ceil(expected.length() * 1.0 / buf.unitSize()); isTrue(buf.unitCount() == size || buf.unitCount() == size + 1); byte[] bytes = expected.getBytes(); synchronized (buf) { for (int i = 0; i < bytes.length; i++) { eq((char) buf.get(i), (char) bytes[i]); } } for (int len = 2; len < 10; len++) { for (int p = 0; p <= buf.size() - len; p++) { String sub = buf.get(new BufRange(p, len)); eq(sub, expected.substring(p, p + len)); } } }
protected Buf buf(String content) { BufGroup bufs = new BufGroup(4); Buf buf = bufs.newBuf(); eq(buf, ""); buf.append(content); return buf; }
@Override public void sendReceive( int toRank, int sendTag, Buf sendBuf, int fromRank, int recvTag, Buf recvBuf) throws IOException { comm.sendReceive( toRank, sendTag, (edu.rit.mp.Buf) sendBuf.getBuffer(), fromRank, recvTag, (edu.rit.mp.Buf) recvBuf.getBuffer()); }
@Override public void scatter(int root, int tag, Buf[] srcBuffers, Buf dstBuffer) throws IOException { if (srcBuffers == null) { comm.scatter(root, null, (edu.rit.mp.Buf) dstBuffer.getBuffer()); return; } edu.rit.mp.Buf[] srcarray = new edu.rit.mp.Buf[srcBuffers.length]; for (int i = 0; i < srcBuffers.length; i++) srcarray[i] = (edu.rit.mp.Buf) srcBuffers[i].getBuffer(); comm.scatter(root, tag, srcarray, (edu.rit.mp.Buf) dstBuffer.getBuffer()); }
public static void main(String... args) throws Exception { DefaultObjectModel om = new DefaultObjectModel(args[1]); om.setWrapper(Class.forName(args[2])); CompactReader rd = new CompactReader(om); String task = args[0]; if (task.equals("roundtrip")) { DefaultBlock result = new DefaultBlock(); ByteArrayOutputStream os = new ByteArrayOutputStream(); CompactWriter wr = new CompactWriter(om, os); int count = 0; long decTime = 0; long encTime = 0; FileInputStream is = new FileInputStream(args[3]); Buf buf = DirectBuf.newInstance(); try { for (; ; ) { if (!buf.fillFrom(is)) break; buf.flip(); result.clear(); os.reset(); long t1 = System.currentTimeMillis(); rd.read(buf, result); long t2 = System.currentTimeMillis(); for (Object o : result) wr.write(o); wr.flush(); long t3 = System.currentTimeMillis(); decTime += t2 - t1; encTime += t3 - t2; count += result.size(); } } finally { is.close(); } System.out.printf( "Decoded %d msgs in %d ms (%.2f msgs/s)%n", count, decTime, 1000 * (double) count / (double) decTime); System.out.printf( "Encoded %d msgs in %d ms (%.2f msgs/s)%n", count, encTime, 1000 * (double) count / (double) encTime); } else throw new RuntimeException("Unknown PerfTest task: " + task); }
@Override public void gather(int root, int tag, Buf srcBuffer, Buf[] dstBuffers) throws IOException { if (dstBuffers == null) { comm.gather(root, tag, (edu.rit.mp.Buf) srcBuffer.getBuffer(), null); return; } edu.rit.mp.Buf[] dstarray = new edu.rit.mp.Buf[dstBuffers.length]; for (int i = 0; i < dstBuffers.length; i++) { dstarray[i] = (edu.rit.mp.Buf) dstBuffers[i].getBuffer(); } comm.gather(root, tag, (edu.rit.mp.Buf) srcBuffer.getBuffer(), dstarray); }
public void write() { if (!isPopulated()) { Flog.warn("Unable to write %s because it's not populated yet.", path); return; } VirtualFile virtualFile = getVirtualFile(); if (virtualFile == null) { virtualFile = createFile(); if (virtualFile == null) { context.errorMessage("The Floobits plugin was unable to write to a file."); return; } } Document d = Buf.getDocumentForVirtualFile(virtualFile); if (d != null) { try { Listener.flooDisable(); d.setReadOnly(false); d.setText(buf); } finally { Listener.flooEnable(); } return; } Flog.warn("Tried to write to null document: %s", path); try { virtualFile.setBinaryContent(buf.getBytes()); } catch (IOException e) { Flog.warn(e); context.errorMessage("The Floobits plugin was unable to write to a file."); } }
public void send_patch(VirtualFile virtualFile) { Document d = Buf.getDocumentForVirtualFile(virtualFile); if (d == null) { Flog.warn("Can't get document to read from disk for sending patch %s", path); return; } send_patch(d.getText()); }
public Long readBuf(Buf buf, long n) { try { long read = buf.pipeFrom(in, n); if (read < 0) return null; return Long.valueOf(read); } catch (IOException e) { throw IOErr.make(e); } }
public void read() { VirtualFile virtualFile = this.getVirtualFile(); if (virtualFile == null) { Flog.warn("Can't get virtual file to read from disk %s", this); return; } Document d = Buf.getDocumentForVirtualFile(virtualFile); if (d == null) { Flog.warn("Can't get document to read from disk %s", this); return; } this.buf = d.getText(); this.md5 = DigestUtils.md5Hex(this.buf); }
@Override public synchronized long checkpoint() { return buf.checkpoint(); }
@Override public synchronized void checkpoint(long checkpoint) { buf.checkpoint(checkpoint); }
@Override public synchronized void setReadOnly(boolean readOnly) { buf.setReadOnly(readOnly); }
@Override public synchronized void append(byte[] bytes, int offset, int length) { buf.append(bytes, offset, length); }
@Override public synchronized long append(String s) { return buf.append(s); }
@Override public synchronized void append(ByteBuffer wrap) { buf.append(wrap); }
@Override public synchronized void put(long position, byte[] bytes, int offset, int length) { buf.put(position, bytes, offset, length); }
@Override public synchronized void put(long position, byte value) { buf.put(position, value); }
@Override public synchronized byte get(long position) { return buf.get(position); }
@Override public synchronized String readLn() { return buf.readLn(); }
@Override public synchronized void append(byte value) { buf.append(value); }
@Override public synchronized String readN(long count) { return buf.readN(count); }
@Override public synchronized long size() { return buf.size(); }
@Override public synchronized byte[] readNbytes(int count) { return buf.readNbytes(count); }
@Override public synchronized long append(ReadableByteChannel channel) throws IOException { return buf.append(channel); }
@Override public synchronized void scanTo(byte sep, Range range, boolean failOnLimit) { buf.scanTo(sep, range, failOnLimit); }
@Override public synchronized void append(byte[] bytes) { buf.append(bytes); }
@Override public synchronized long scanTo(byte sep1, byte sep2, Range range, boolean failOnLimit) { return buf.scanTo(sep1, sep2, range, failOnLimit); }
@Override public synchronized String data() { return buf.data(); }
@Override public synchronized void scanLnLn(Ranges ranges, LongWrap result, byte end1, byte end2) { buf.scanLnLn(ranges, result, end1, end2); }