repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
PascalUrso/ReplicationBenchmark
src/jbenchmarker/woot/original/WootOriginalNode.java
// Path: src/jbenchmarker/woot/WootIdentifier.java // public class WootIdentifier implements Comparable<WootIdentifier> { // public static final WootIdentifier IB = new WootIdentifier(-1,0); // public static final WootIdentifier IE = new WootIdentifier(-1,1);; // // public WootIdentifier(int replica, int clock) { // this.replica = replica; // this.clock = clock; // } // // private int replica; // private int clock; // // public int getClock() { // return clock; // } // // public int getReplica() { // return replica; // } // // // @Override // public int compareTo(WootIdentifier t) { // if (this.replica == t.replica) // return this.clock - t.clock; // else // return this.replica - t.replica; // } // // public WootIdentifier clone() { // return new WootIdentifier(replica,clock); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final WootIdentifier other = (WootIdentifier) obj; // if (this.replica != other.replica) { // return false; // } // if (this.clock != other.clock) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 13 * hash + this.replica; // hash = 13 * hash + this.clock; // return hash; // } // } // // Path: src/jbenchmarker/woot/WootNode.java // public abstract class WootNode { // // private WootIdentifier id; // own identifier // // private char content; // private boolean visible; // // public WootNode(WootIdentifier id, char content, boolean visible) { // this.id = id; // this.content = content; // this.visible = visible; // } // // public WootIdentifier getId() { // return id; // } // // public char getContent() { // return content; // } // // public boolean isVisible() { // return visible; // } // // public void setVisible(boolean visible) { // this.visible = visible; // } // }
import jbenchmarker.woot.WootIdentifier; import jbenchmarker.woot.WootNode;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.woot.original; /** * * @author urso */ public class WootOriginalNode extends WootNode { private WootOriginalNode cp; // previous node private WootOriginalNode cn; // next node
// Path: src/jbenchmarker/woot/WootIdentifier.java // public class WootIdentifier implements Comparable<WootIdentifier> { // public static final WootIdentifier IB = new WootIdentifier(-1,0); // public static final WootIdentifier IE = new WootIdentifier(-1,1);; // // public WootIdentifier(int replica, int clock) { // this.replica = replica; // this.clock = clock; // } // // private int replica; // private int clock; // // public int getClock() { // return clock; // } // // public int getReplica() { // return replica; // } // // // @Override // public int compareTo(WootIdentifier t) { // if (this.replica == t.replica) // return this.clock - t.clock; // else // return this.replica - t.replica; // } // // public WootIdentifier clone() { // return new WootIdentifier(replica,clock); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final WootIdentifier other = (WootIdentifier) obj; // if (this.replica != other.replica) { // return false; // } // if (this.clock != other.clock) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 13 * hash + this.replica; // hash = 13 * hash + this.clock; // return hash; // } // } // // Path: src/jbenchmarker/woot/WootNode.java // public abstract class WootNode { // // private WootIdentifier id; // own identifier // // private char content; // private boolean visible; // // public WootNode(WootIdentifier id, char content, boolean visible) { // this.id = id; // this.content = content; // this.visible = visible; // } // // public WootIdentifier getId() { // return id; // } // // public char getContent() { // return content; // } // // public boolean isVisible() { // return visible; // } // // public void setVisible(boolean visible) { // this.visible = visible; // } // } // Path: src/jbenchmarker/woot/original/WootOriginalNode.java import jbenchmarker.woot.WootIdentifier; import jbenchmarker.woot.WootNode; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.woot.original; /** * * @author urso */ public class WootOriginalNode extends WootNode { private WootOriginalNode cp; // previous node private WootOriginalNode cn; // next node
public static final WootOriginalNode CB = new WootOriginalNode(WootIdentifier.IB, null, null, ' ', false);
PascalUrso/ReplicationBenchmark
src/jbenchmarker/woot/WootDocument.java
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // }
import jbenchmarker.trace.TraceOperation; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import jbenchmarker.core.Document; import jbenchmarker.core.Operation;
} @Override public String view() { StringBuilder s = new StringBuilder(); for (WootNode w : elements) if (w.isVisible()) s.append(w.getContent()); return s.toString(); } public int find(WootIdentifier id) { return findAfter(0, id); } public boolean has(WootIdentifier id) { for (N n : elements) if (n.getId().equals(id)) return true; return false; } public int findAfter(int d, WootIdentifier id) { ListIterator<N> it = elements.listIterator(d); while (it.hasNext()) { if (it.next().getId().equals(id)) return d; d++; } throw new NoSuchElementException("Don't find " + id + " after position " + d); } @Override
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // Path: src/jbenchmarker/woot/WootDocument.java import jbenchmarker.trace.TraceOperation; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import jbenchmarker.core.Document; import jbenchmarker.core.Operation; } @Override public String view() { StringBuilder s = new StringBuilder(); for (WootNode w : elements) if (w.isVisible()) s.append(w.getContent()); return s.toString(); } public int find(WootIdentifier id) { return findAfter(0, id); } public boolean has(WootIdentifier id) { for (N n : elements) if (n.getId().equals(id)) return true; return false; } public int findAfter(int d, WootIdentifier id) { ListIterator<N> it = elements.listIterator(d); while (it.hasNext()) { if (it.next().getId().equals(id)) return d; d++; } throw new NoSuchElementException("Don't find " + id + " after position " + d); } @Override
public void applyLocal(Operation op) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/woot/WootDocument.java
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // }
import jbenchmarker.trace.TraceOperation; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import jbenchmarker.core.Document; import jbenchmarker.core.Operation;
public String view() { StringBuilder s = new StringBuilder(); for (WootNode w : elements) if (w.isVisible()) s.append(w.getContent()); return s.toString(); } public int find(WootIdentifier id) { return findAfter(0, id); } public boolean has(WootIdentifier id) { for (N n : elements) if (n.getId().equals(id)) return true; return false; } public int findAfter(int d, WootIdentifier id) { ListIterator<N> it = elements.listIterator(d); while (it.hasNext()) { if (it.next().getId().equals(id)) return d; d++; } throw new NoSuchElementException("Don't find " + id + " after position " + d); } @Override public void applyLocal(Operation op) { WootOperation wop = (WootOperation) op;
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // Path: src/jbenchmarker/woot/WootDocument.java import jbenchmarker.trace.TraceOperation; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import jbenchmarker.core.Document; import jbenchmarker.core.Operation; public String view() { StringBuilder s = new StringBuilder(); for (WootNode w : elements) if (w.isVisible()) s.append(w.getContent()); return s.toString(); } public int find(WootIdentifier id) { return findAfter(0, id); } public boolean has(WootIdentifier id) { for (N n : elements) if (n.getId().equals(id)) return true; return false; } public int findAfter(int d, WootIdentifier id) { ListIterator<N> it = elements.listIterator(d); while (it.hasNext()) { if (it.next().getId().equals(id)) return d; d++; } throw new NoSuchElementException("Don't find " + id + " after position " + d); } @Override public void applyLocal(Operation op) { WootOperation wop = (WootOperation) op;
if (wop.getType() == TraceOperation.OpType.del) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/ot/OperationGarbageCollector.java
// Path: src/jbenchmarker/core/VectorClock.java // public class VectorClock extends TreeMap<Integer, Integer> { // // public VectorClock() { // super(); // } // // // TODO: test me, plz // public VectorClock(VectorClock siteVC) { // super(siteVC); // } // // /* // * Is this VC is ready to integrate O ? // * true iff VCr = Or - 1 && for all i!=r, VCi >= Oi // */ // public boolean readyFor(int r, VectorClock O) { // if (this.getSafe(r) != O.get(r) - 1) { // return false; // } // Iterator<Map.Entry<Integer, Integer>> it = O.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> e = it.next(); // if ((e.getKey() != r) && (this.getSafe(e.getKey()) < e.getValue())) { // return false; // } // } // return true; // } // // /** // * Get the sum of all entries // * added by Roh. // */ // public int getSum(){ // int sum = 0; // Iterator<Map.Entry<Integer, Integer>> it = this.entrySet().iterator(); // while (it.hasNext()) sum+= it.next().getValue(); // return sum; // } // // /* // * Increment an entry. // */ // public void inc(int r) { // put(r, getSafe(r) + 1); // } // // /* // * Returns the entry for replica r. 0 if none. // */ // public int getSafe(int r) { // Integer v = get(r); // return (v != null) ? v : 0; // } // // /* // * Is this VC > T ? // * true iff for all i, VCi >= Ti and exists j VCj > Tj // */ // public boolean greaterThan(VectorClock T) { // boolean gt = false; // Iterator<Map.Entry<Integer, Integer>> it = T.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (this.getSafe(i.getKey()) < i.getValue()) { // return false; // } else if (this.getSafe(i.getKey()) > i.getValue()) { // gt = true; // } // } // if (gt) { // return true; // } // it = this.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (T.getSafe(i.getKey()) < i.getValue()) { // return true; // } // } // return false; // } // // /* // * Is this VC // T ? // * true iff nor VC > T nor T > VC // */ // public boolean concurrent(VectorClock T) { // return !(this.greaterThan(T) || T.greaterThan(this)); // } // // /** // * Sets each entry of the VC to max(VCi, Oi) // */ // public void upTo(VectorClock O) { // for (Entry<Integer, Integer> k : O.entrySet()) { // if (k.getValue() > this.getSafe(k.getKey())) { // this.put(k.getKey(), k.getValue()); // } // } // } // // @Override // public boolean equals(Object obj) { // if (obj == null || getClass() != obj.getClass()) { // return false; // } // // final VectorClock other = (VectorClock) obj; // // Set<Integer> h = new HashSet<Integer>(this.keySet()); // h.addAll(other.keySet()); // // for (Integer k : h) { // if (this.getSafe(k) != other.getSafe(k)) { // return false; // } // } // return true; // } // // /* // * computes minimal vector from current and vector clocks provided in parameters. // * for each vc in {this} U otherVectorClocks, for each i in min, min[i] <= vc[i] // */ // public VectorClock min(Collection<VectorClock> otherVectorClocks) { // VectorClock min = new VectorClock(this); // // for (VectorClock clock : otherVectorClocks) { // Iterator<Map.Entry<Integer, Integer>> componentIterator = clock.entrySet().iterator(); // while (componentIterator.hasNext()) { // Map.Entry<Integer, Integer> i = componentIterator.next(); // Integer key = i.getKey(); // min.put(key, Math.min(min.getSafe(key), i.getValue())); // } // } // return min; // } // }
import java.util.Iterator; import java.util.Map; import java.util.TreeMap; import java.util.logging.Level; import java.util.logging.Logger; import jbenchmarker.core.VectorClock;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.ot; /** * * @author oster */ public class OperationGarbageCollector { private SOCT2MergeAlgorithm mergeAlgorithm;
// Path: src/jbenchmarker/core/VectorClock.java // public class VectorClock extends TreeMap<Integer, Integer> { // // public VectorClock() { // super(); // } // // // TODO: test me, plz // public VectorClock(VectorClock siteVC) { // super(siteVC); // } // // /* // * Is this VC is ready to integrate O ? // * true iff VCr = Or - 1 && for all i!=r, VCi >= Oi // */ // public boolean readyFor(int r, VectorClock O) { // if (this.getSafe(r) != O.get(r) - 1) { // return false; // } // Iterator<Map.Entry<Integer, Integer>> it = O.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> e = it.next(); // if ((e.getKey() != r) && (this.getSafe(e.getKey()) < e.getValue())) { // return false; // } // } // return true; // } // // /** // * Get the sum of all entries // * added by Roh. // */ // public int getSum(){ // int sum = 0; // Iterator<Map.Entry<Integer, Integer>> it = this.entrySet().iterator(); // while (it.hasNext()) sum+= it.next().getValue(); // return sum; // } // // /* // * Increment an entry. // */ // public void inc(int r) { // put(r, getSafe(r) + 1); // } // // /* // * Returns the entry for replica r. 0 if none. // */ // public int getSafe(int r) { // Integer v = get(r); // return (v != null) ? v : 0; // } // // /* // * Is this VC > T ? // * true iff for all i, VCi >= Ti and exists j VCj > Tj // */ // public boolean greaterThan(VectorClock T) { // boolean gt = false; // Iterator<Map.Entry<Integer, Integer>> it = T.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (this.getSafe(i.getKey()) < i.getValue()) { // return false; // } else if (this.getSafe(i.getKey()) > i.getValue()) { // gt = true; // } // } // if (gt) { // return true; // } // it = this.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (T.getSafe(i.getKey()) < i.getValue()) { // return true; // } // } // return false; // } // // /* // * Is this VC // T ? // * true iff nor VC > T nor T > VC // */ // public boolean concurrent(VectorClock T) { // return !(this.greaterThan(T) || T.greaterThan(this)); // } // // /** // * Sets each entry of the VC to max(VCi, Oi) // */ // public void upTo(VectorClock O) { // for (Entry<Integer, Integer> k : O.entrySet()) { // if (k.getValue() > this.getSafe(k.getKey())) { // this.put(k.getKey(), k.getValue()); // } // } // } // // @Override // public boolean equals(Object obj) { // if (obj == null || getClass() != obj.getClass()) { // return false; // } // // final VectorClock other = (VectorClock) obj; // // Set<Integer> h = new HashSet<Integer>(this.keySet()); // h.addAll(other.keySet()); // // for (Integer k : h) { // if (this.getSafe(k) != other.getSafe(k)) { // return false; // } // } // return true; // } // // /* // * computes minimal vector from current and vector clocks provided in parameters. // * for each vc in {this} U otherVectorClocks, for each i in min, min[i] <= vc[i] // */ // public VectorClock min(Collection<VectorClock> otherVectorClocks) { // VectorClock min = new VectorClock(this); // // for (VectorClock clock : otherVectorClocks) { // Iterator<Map.Entry<Integer, Integer>> componentIterator = clock.entrySet().iterator(); // while (componentIterator.hasNext()) { // Map.Entry<Integer, Integer> i = componentIterator.next(); // Integer key = i.getKey(); // min.put(key, Math.min(min.getSafe(key), i.getValue())); // } // } // return min; // } // } // Path: src/jbenchmarker/ot/OperationGarbageCollector.java import java.util.Iterator; import java.util.Map; import java.util.TreeMap; import java.util.logging.Level; import java.util.logging.Logger; import jbenchmarker.core.VectorClock; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.ot; /** * * @author oster */ public class OperationGarbageCollector { private SOCT2MergeAlgorithm mergeAlgorithm;
private Map<Integer, VectorClock> clocksOfAllSites = new TreeMap<Integer, VectorClock>();
PascalUrso/ReplicationBenchmark
src/jbenchmarker/logoot/LogootFactory.java
// Path: src/jbenchmarker/core/MergeAlgorithm.java // public abstract class MergeAlgorithm { // // Replica identifier // private int replicaNb; // // // Supported Document // private Document doc; // // // Local operations generated // private List<TraceOperation> localHistory; // // // All operations executed // private List<Operation> history; // // // Local operations generated time map : size history -> exec time // private TreeMap<Integer, Long> localExecTime; // // // All operations executed // private List<Long> execTime; // // /* // * Constructor // */ // public MergeAlgorithm(Document doc, int r) { // this(); // this.replicaNb = r; // this.doc = doc; // } // // public MergeAlgorithm() { // this.execTime = new ArrayList<Long>(); // this.localExecTime = new TreeMap<Integer, Long>(); // this.history = new ArrayList<Operation>(); // this.localHistory = new ArrayList<TraceOperation>(); // } // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract void integrateLocal(Operation op) throws IncorrectTrace; // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract List<Operation> generateLocal(TraceOperation opt) throws IncorrectTrace; // // // // /* // * Integration of a remote operation // * Adds operation in history and execution time // */ // public void integrate(Operation op) throws IncorrectTrace { // long startTime = System.nanoTime(); // history.add(op); // integrateLocal(op); // execTime.add(System.nanoTime() - startTime); // } // // /** // * Generation of a local trace operation, returns a patch of operation // * Throws IncorrectTrace iff operation is not generable in the context. // **/ // public List<Operation> generate(TraceOperation opt) throws IncorrectTrace { // localHistory.add(opt); // long startTime = System.nanoTime(); // List<Operation> l = generateLocal(opt); // long t = System.nanoTime() - startTime, oh = t/l.size(); // int i = history.size(); // localExecTime.put(i,t); // for (Operation o : l) { // execTime.add(oh); // history.add(o); // i++; // } // return l; // } // // public List<Long> getExecTime() { // return execTime; // } // // public List<Operation> getHistory() { // return history; // } // // public TreeMap<Integer, Long> getLocalExecTime() { // return localExecTime; // } // // public List<TraceOperation> getLocalHistory() { // return localHistory; // } // // public Document getDoc() { // return doc; // } // // public void setDoc(Document doc) { // this.doc = doc; // } // // public void setReplicaNb(int replicaNb) { // this.replicaNb = replicaNb; // } // // public int getReplicaNb() { // return replicaNb; // } // // public void reset() { // this.execTime.clear(); // this.localExecTime.clear(); // this.history.clear(); // this.localHistory.clear(); // } // } // // Path: src/jbenchmarker/core/ReplicaFactory.java // public abstract class ReplicaFactory { // public abstract MergeAlgorithm createReplica(int r); // }
import jbenchmarker.core.MergeAlgorithm; import jbenchmarker.core.ReplicaFactory;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.logoot; /** * * @author urso */ public class LogootFactory extends ReplicaFactory { @Override
// Path: src/jbenchmarker/core/MergeAlgorithm.java // public abstract class MergeAlgorithm { // // Replica identifier // private int replicaNb; // // // Supported Document // private Document doc; // // // Local operations generated // private List<TraceOperation> localHistory; // // // All operations executed // private List<Operation> history; // // // Local operations generated time map : size history -> exec time // private TreeMap<Integer, Long> localExecTime; // // // All operations executed // private List<Long> execTime; // // /* // * Constructor // */ // public MergeAlgorithm(Document doc, int r) { // this(); // this.replicaNb = r; // this.doc = doc; // } // // public MergeAlgorithm() { // this.execTime = new ArrayList<Long>(); // this.localExecTime = new TreeMap<Integer, Long>(); // this.history = new ArrayList<Operation>(); // this.localHistory = new ArrayList<TraceOperation>(); // } // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract void integrateLocal(Operation op) throws IncorrectTrace; // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract List<Operation> generateLocal(TraceOperation opt) throws IncorrectTrace; // // // // /* // * Integration of a remote operation // * Adds operation in history and execution time // */ // public void integrate(Operation op) throws IncorrectTrace { // long startTime = System.nanoTime(); // history.add(op); // integrateLocal(op); // execTime.add(System.nanoTime() - startTime); // } // // /** // * Generation of a local trace operation, returns a patch of operation // * Throws IncorrectTrace iff operation is not generable in the context. // **/ // public List<Operation> generate(TraceOperation opt) throws IncorrectTrace { // localHistory.add(opt); // long startTime = System.nanoTime(); // List<Operation> l = generateLocal(opt); // long t = System.nanoTime() - startTime, oh = t/l.size(); // int i = history.size(); // localExecTime.put(i,t); // for (Operation o : l) { // execTime.add(oh); // history.add(o); // i++; // } // return l; // } // // public List<Long> getExecTime() { // return execTime; // } // // public List<Operation> getHistory() { // return history; // } // // public TreeMap<Integer, Long> getLocalExecTime() { // return localExecTime; // } // // public List<TraceOperation> getLocalHistory() { // return localHistory; // } // // public Document getDoc() { // return doc; // } // // public void setDoc(Document doc) { // this.doc = doc; // } // // public void setReplicaNb(int replicaNb) { // this.replicaNb = replicaNb; // } // // public int getReplicaNb() { // return replicaNb; // } // // public void reset() { // this.execTime.clear(); // this.localExecTime.clear(); // this.history.clear(); // this.localHistory.clear(); // } // } // // Path: src/jbenchmarker/core/ReplicaFactory.java // public abstract class ReplicaFactory { // public abstract MergeAlgorithm createReplica(int r); // } // Path: src/jbenchmarker/logoot/LogootFactory.java import jbenchmarker.core.MergeAlgorithm; import jbenchmarker.core.ReplicaFactory; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.logoot; /** * * @author urso */ public class LogootFactory extends ReplicaFactory { @Override
public MergeAlgorithm createReplica(int r) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/sim/PlaceboFactory.java
// Path: src/jbenchmarker/trace/IncorrectTrace.java // public class IncorrectTrace extends Exception { // public IncorrectTrace() { // } // // public IncorrectTrace(Throwable thrwbl) { // super(thrwbl); // } // // public IncorrectTrace(String string, Throwable thrwbl) { // super(string, thrwbl); // } // // public IncorrectTrace(String string) { // super(string); // } // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // }
import java.util.List; import jbenchmarker.core.*; import jbenchmarker.trace.IncorrectTrace; import jbenchmarker.trace.TraceOperation;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.sim; /** * Used to measure the base memory/time required to simulate a trace. * @author urso */ public class PlaceboFactory extends ReplicaFactory { public static class PlaceboOperation extends Operation {
// Path: src/jbenchmarker/trace/IncorrectTrace.java // public class IncorrectTrace extends Exception { // public IncorrectTrace() { // } // // public IncorrectTrace(Throwable thrwbl) { // super(thrwbl); // } // // public IncorrectTrace(String string, Throwable thrwbl) { // super(string, thrwbl); // } // // public IncorrectTrace(String string) { // super(string); // } // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // Path: src/jbenchmarker/sim/PlaceboFactory.java import java.util.List; import jbenchmarker.core.*; import jbenchmarker.trace.IncorrectTrace; import jbenchmarker.trace.TraceOperation; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.sim; /** * Used to measure the base memory/time required to simulate a trace. * @author urso */ public class PlaceboFactory extends ReplicaFactory { public static class PlaceboOperation extends Operation {
public PlaceboOperation(TraceOperation o) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/sim/PlaceboFactory.java
// Path: src/jbenchmarker/trace/IncorrectTrace.java // public class IncorrectTrace extends Exception { // public IncorrectTrace() { // } // // public IncorrectTrace(Throwable thrwbl) { // super(thrwbl); // } // // public IncorrectTrace(String string, Throwable thrwbl) { // super(string, thrwbl); // } // // public IncorrectTrace(String string) { // super(string); // } // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // }
import java.util.List; import jbenchmarker.core.*; import jbenchmarker.trace.IncorrectTrace; import jbenchmarker.trace.TraceOperation;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.sim; /** * Used to measure the base memory/time required to simulate a trace. * @author urso */ public class PlaceboFactory extends ReplicaFactory { public static class PlaceboOperation extends Operation { public PlaceboOperation(TraceOperation o) { super(o); } @Override public Operation clone() { return new PlaceboOperation(this.getOriginalOp()); } } @Override public MergeAlgorithm createReplica(int r) { return new MergeAlgorithm(new Document() { public String view() { return ""; } public void applyLocal(Operation op) { } }, r) {
// Path: src/jbenchmarker/trace/IncorrectTrace.java // public class IncorrectTrace extends Exception { // public IncorrectTrace() { // } // // public IncorrectTrace(Throwable thrwbl) { // super(thrwbl); // } // // public IncorrectTrace(String string, Throwable thrwbl) { // super(string, thrwbl); // } // // public IncorrectTrace(String string) { // super(string); // } // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // Path: src/jbenchmarker/sim/PlaceboFactory.java import java.util.List; import jbenchmarker.core.*; import jbenchmarker.trace.IncorrectTrace; import jbenchmarker.trace.TraceOperation; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.sim; /** * Used to measure the base memory/time required to simulate a trace. * @author urso */ public class PlaceboFactory extends ReplicaFactory { public static class PlaceboOperation extends Operation { public PlaceboOperation(TraceOperation o) { super(o); } @Override public Operation clone() { return new PlaceboOperation(this.getOriginalOp()); } } @Override public MergeAlgorithm createReplica(int r) { return new MergeAlgorithm(new Document() { public String view() { return ""; } public void applyLocal(Operation op) { } }, r) {
protected void integrateLocal(Operation op) throws IncorrectTrace {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/woot/wooth/WootHFactory.java
// Path: src/jbenchmarker/core/MergeAlgorithm.java // public abstract class MergeAlgorithm { // // Replica identifier // private int replicaNb; // // // Supported Document // private Document doc; // // // Local operations generated // private List<TraceOperation> localHistory; // // // All operations executed // private List<Operation> history; // // // Local operations generated time map : size history -> exec time // private TreeMap<Integer, Long> localExecTime; // // // All operations executed // private List<Long> execTime; // // /* // * Constructor // */ // public MergeAlgorithm(Document doc, int r) { // this(); // this.replicaNb = r; // this.doc = doc; // } // // public MergeAlgorithm() { // this.execTime = new ArrayList<Long>(); // this.localExecTime = new TreeMap<Integer, Long>(); // this.history = new ArrayList<Operation>(); // this.localHistory = new ArrayList<TraceOperation>(); // } // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract void integrateLocal(Operation op) throws IncorrectTrace; // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract List<Operation> generateLocal(TraceOperation opt) throws IncorrectTrace; // // // // /* // * Integration of a remote operation // * Adds operation in history and execution time // */ // public void integrate(Operation op) throws IncorrectTrace { // long startTime = System.nanoTime(); // history.add(op); // integrateLocal(op); // execTime.add(System.nanoTime() - startTime); // } // // /** // * Generation of a local trace operation, returns a patch of operation // * Throws IncorrectTrace iff operation is not generable in the context. // **/ // public List<Operation> generate(TraceOperation opt) throws IncorrectTrace { // localHistory.add(opt); // long startTime = System.nanoTime(); // List<Operation> l = generateLocal(opt); // long t = System.nanoTime() - startTime, oh = t/l.size(); // int i = history.size(); // localExecTime.put(i,t); // for (Operation o : l) { // execTime.add(oh); // history.add(o); // i++; // } // return l; // } // // public List<Long> getExecTime() { // return execTime; // } // // public List<Operation> getHistory() { // return history; // } // // public TreeMap<Integer, Long> getLocalExecTime() { // return localExecTime; // } // // public List<TraceOperation> getLocalHistory() { // return localHistory; // } // // public Document getDoc() { // return doc; // } // // public void setDoc(Document doc) { // this.doc = doc; // } // // public void setReplicaNb(int replicaNb) { // this.replicaNb = replicaNb; // } // // public int getReplicaNb() { // return replicaNb; // } // // public void reset() { // this.execTime.clear(); // this.localExecTime.clear(); // this.history.clear(); // this.localHistory.clear(); // } // } // // Path: src/jbenchmarker/core/ReplicaFactory.java // public abstract class ReplicaFactory { // public abstract MergeAlgorithm createReplica(int r); // }
import jbenchmarker.core.MergeAlgorithm; import jbenchmarker.core.ReplicaFactory;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.woot.wooth; /** * * @author urso */ public class WootHFactory extends ReplicaFactory { @Override
// Path: src/jbenchmarker/core/MergeAlgorithm.java // public abstract class MergeAlgorithm { // // Replica identifier // private int replicaNb; // // // Supported Document // private Document doc; // // // Local operations generated // private List<TraceOperation> localHistory; // // // All operations executed // private List<Operation> history; // // // Local operations generated time map : size history -> exec time // private TreeMap<Integer, Long> localExecTime; // // // All operations executed // private List<Long> execTime; // // /* // * Constructor // */ // public MergeAlgorithm(Document doc, int r) { // this(); // this.replicaNb = r; // this.doc = doc; // } // // public MergeAlgorithm() { // this.execTime = new ArrayList<Long>(); // this.localExecTime = new TreeMap<Integer, Long>(); // this.history = new ArrayList<Operation>(); // this.localHistory = new ArrayList<TraceOperation>(); // } // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract void integrateLocal(Operation op) throws IncorrectTrace; // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract List<Operation> generateLocal(TraceOperation opt) throws IncorrectTrace; // // // // /* // * Integration of a remote operation // * Adds operation in history and execution time // */ // public void integrate(Operation op) throws IncorrectTrace { // long startTime = System.nanoTime(); // history.add(op); // integrateLocal(op); // execTime.add(System.nanoTime() - startTime); // } // // /** // * Generation of a local trace operation, returns a patch of operation // * Throws IncorrectTrace iff operation is not generable in the context. // **/ // public List<Operation> generate(TraceOperation opt) throws IncorrectTrace { // localHistory.add(opt); // long startTime = System.nanoTime(); // List<Operation> l = generateLocal(opt); // long t = System.nanoTime() - startTime, oh = t/l.size(); // int i = history.size(); // localExecTime.put(i,t); // for (Operation o : l) { // execTime.add(oh); // history.add(o); // i++; // } // return l; // } // // public List<Long> getExecTime() { // return execTime; // } // // public List<Operation> getHistory() { // return history; // } // // public TreeMap<Integer, Long> getLocalExecTime() { // return localExecTime; // } // // public List<TraceOperation> getLocalHistory() { // return localHistory; // } // // public Document getDoc() { // return doc; // } // // public void setDoc(Document doc) { // this.doc = doc; // } // // public void setReplicaNb(int replicaNb) { // this.replicaNb = replicaNb; // } // // public int getReplicaNb() { // return replicaNb; // } // // public void reset() { // this.execTime.clear(); // this.localExecTime.clear(); // this.history.clear(); // this.localHistory.clear(); // } // } // // Path: src/jbenchmarker/core/ReplicaFactory.java // public abstract class ReplicaFactory { // public abstract MergeAlgorithm createReplica(int r); // } // Path: src/jbenchmarker/woot/wooth/WootHFactory.java import jbenchmarker.core.MergeAlgorithm; import jbenchmarker.core.ReplicaFactory; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.woot.wooth; /** * * @author urso */ public class WootHFactory extends ReplicaFactory { @Override
public MergeAlgorithm createReplica(int r) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/ot/SOCT2Factory.java
// Path: src/jbenchmarker/core/MergeAlgorithm.java // public abstract class MergeAlgorithm { // // Replica identifier // private int replicaNb; // // // Supported Document // private Document doc; // // // Local operations generated // private List<TraceOperation> localHistory; // // // All operations executed // private List<Operation> history; // // // Local operations generated time map : size history -> exec time // private TreeMap<Integer, Long> localExecTime; // // // All operations executed // private List<Long> execTime; // // /* // * Constructor // */ // public MergeAlgorithm(Document doc, int r) { // this(); // this.replicaNb = r; // this.doc = doc; // } // // public MergeAlgorithm() { // this.execTime = new ArrayList<Long>(); // this.localExecTime = new TreeMap<Integer, Long>(); // this.history = new ArrayList<Operation>(); // this.localHistory = new ArrayList<TraceOperation>(); // } // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract void integrateLocal(Operation op) throws IncorrectTrace; // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract List<Operation> generateLocal(TraceOperation opt) throws IncorrectTrace; // // // // /* // * Integration of a remote operation // * Adds operation in history and execution time // */ // public void integrate(Operation op) throws IncorrectTrace { // long startTime = System.nanoTime(); // history.add(op); // integrateLocal(op); // execTime.add(System.nanoTime() - startTime); // } // // /** // * Generation of a local trace operation, returns a patch of operation // * Throws IncorrectTrace iff operation is not generable in the context. // **/ // public List<Operation> generate(TraceOperation opt) throws IncorrectTrace { // localHistory.add(opt); // long startTime = System.nanoTime(); // List<Operation> l = generateLocal(opt); // long t = System.nanoTime() - startTime, oh = t/l.size(); // int i = history.size(); // localExecTime.put(i,t); // for (Operation o : l) { // execTime.add(oh); // history.add(o); // i++; // } // return l; // } // // public List<Long> getExecTime() { // return execTime; // } // // public List<Operation> getHistory() { // return history; // } // // public TreeMap<Integer, Long> getLocalExecTime() { // return localExecTime; // } // // public List<TraceOperation> getLocalHistory() { // return localHistory; // } // // public Document getDoc() { // return doc; // } // // public void setDoc(Document doc) { // this.doc = doc; // } // // public void setReplicaNb(int replicaNb) { // this.replicaNb = replicaNb; // } // // public int getReplicaNb() { // return replicaNb; // } // // public void reset() { // this.execTime.clear(); // this.localExecTime.clear(); // this.history.clear(); // this.localHistory.clear(); // } // } // // Path: src/jbenchmarker/core/ReplicaFactory.java // public abstract class ReplicaFactory { // public abstract MergeAlgorithm createReplica(int r); // }
import jbenchmarker.core.MergeAlgorithm; import jbenchmarker.core.ReplicaFactory;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.ot; /** * * @author oster */ public class SOCT2Factory extends ReplicaFactory { @Override
// Path: src/jbenchmarker/core/MergeAlgorithm.java // public abstract class MergeAlgorithm { // // Replica identifier // private int replicaNb; // // // Supported Document // private Document doc; // // // Local operations generated // private List<TraceOperation> localHistory; // // // All operations executed // private List<Operation> history; // // // Local operations generated time map : size history -> exec time // private TreeMap<Integer, Long> localExecTime; // // // All operations executed // private List<Long> execTime; // // /* // * Constructor // */ // public MergeAlgorithm(Document doc, int r) { // this(); // this.replicaNb = r; // this.doc = doc; // } // // public MergeAlgorithm() { // this.execTime = new ArrayList<Long>(); // this.localExecTime = new TreeMap<Integer, Long>(); // this.history = new ArrayList<Operation>(); // this.localHistory = new ArrayList<TraceOperation>(); // } // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract void integrateLocal(Operation op) throws IncorrectTrace; // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract List<Operation> generateLocal(TraceOperation opt) throws IncorrectTrace; // // // // /* // * Integration of a remote operation // * Adds operation in history and execution time // */ // public void integrate(Operation op) throws IncorrectTrace { // long startTime = System.nanoTime(); // history.add(op); // integrateLocal(op); // execTime.add(System.nanoTime() - startTime); // } // // /** // * Generation of a local trace operation, returns a patch of operation // * Throws IncorrectTrace iff operation is not generable in the context. // **/ // public List<Operation> generate(TraceOperation opt) throws IncorrectTrace { // localHistory.add(opt); // long startTime = System.nanoTime(); // List<Operation> l = generateLocal(opt); // long t = System.nanoTime() - startTime, oh = t/l.size(); // int i = history.size(); // localExecTime.put(i,t); // for (Operation o : l) { // execTime.add(oh); // history.add(o); // i++; // } // return l; // } // // public List<Long> getExecTime() { // return execTime; // } // // public List<Operation> getHistory() { // return history; // } // // public TreeMap<Integer, Long> getLocalExecTime() { // return localExecTime; // } // // public List<TraceOperation> getLocalHistory() { // return localHistory; // } // // public Document getDoc() { // return doc; // } // // public void setDoc(Document doc) { // this.doc = doc; // } // // public void setReplicaNb(int replicaNb) { // this.replicaNb = replicaNb; // } // // public int getReplicaNb() { // return replicaNb; // } // // public void reset() { // this.execTime.clear(); // this.localExecTime.clear(); // this.history.clear(); // this.localHistory.clear(); // } // } // // Path: src/jbenchmarker/core/ReplicaFactory.java // public abstract class ReplicaFactory { // public abstract MergeAlgorithm createReplica(int r); // } // Path: src/jbenchmarker/ot/SOCT2Factory.java import jbenchmarker.core.MergeAlgorithm; import jbenchmarker.core.ReplicaFactory; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.ot; /** * * @author oster */ public class SOCT2Factory extends ReplicaFactory { @Override
public MergeAlgorithm createReplica(int siteId) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/logoot/LogootOperation.java
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del };
import java.util.ArrayList; import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.logoot; /** * * @author mehdi */ public class LogootOperation extends Operation { private LogootIdentifier identif; private char content;
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del }; // Path: src/jbenchmarker/logoot/LogootOperation.java import java.util.ArrayList; import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.logoot; /** * * @author mehdi */ public class LogootOperation extends Operation { private LogootIdentifier identif; private char content;
private LogootOperation(TraceOperation o, LogootIdentifier identif, char content) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/logoot/LogootOperation.java
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del };
import java.util.ArrayList; import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.logoot; /** * * @author mehdi */ public class LogootOperation extends Operation { private LogootIdentifier identif; private char content; private LogootOperation(TraceOperation o, LogootIdentifier identif, char content) { super(o); this.identif = identif; this.content = content; }
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del }; // Path: src/jbenchmarker/logoot/LogootOperation.java import java.util.ArrayList; import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.logoot; /** * * @author mehdi */ public class LogootOperation extends Operation { private LogootIdentifier identif; private char content; private LogootOperation(TraceOperation o, LogootIdentifier identif, char content) { super(o); this.identif = identif; this.content = content; }
public OpType getType() {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/rga/RGAFactory.java
// Path: src/jbenchmarker/core/MergeAlgorithm.java // public abstract class MergeAlgorithm { // // Replica identifier // private int replicaNb; // // // Supported Document // private Document doc; // // // Local operations generated // private List<TraceOperation> localHistory; // // // All operations executed // private List<Operation> history; // // // Local operations generated time map : size history -> exec time // private TreeMap<Integer, Long> localExecTime; // // // All operations executed // private List<Long> execTime; // // /* // * Constructor // */ // public MergeAlgorithm(Document doc, int r) { // this(); // this.replicaNb = r; // this.doc = doc; // } // // public MergeAlgorithm() { // this.execTime = new ArrayList<Long>(); // this.localExecTime = new TreeMap<Integer, Long>(); // this.history = new ArrayList<Operation>(); // this.localHistory = new ArrayList<TraceOperation>(); // } // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract void integrateLocal(Operation op) throws IncorrectTrace; // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract List<Operation> generateLocal(TraceOperation opt) throws IncorrectTrace; // // // // /* // * Integration of a remote operation // * Adds operation in history and execution time // */ // public void integrate(Operation op) throws IncorrectTrace { // long startTime = System.nanoTime(); // history.add(op); // integrateLocal(op); // execTime.add(System.nanoTime() - startTime); // } // // /** // * Generation of a local trace operation, returns a patch of operation // * Throws IncorrectTrace iff operation is not generable in the context. // **/ // public List<Operation> generate(TraceOperation opt) throws IncorrectTrace { // localHistory.add(opt); // long startTime = System.nanoTime(); // List<Operation> l = generateLocal(opt); // long t = System.nanoTime() - startTime, oh = t/l.size(); // int i = history.size(); // localExecTime.put(i,t); // for (Operation o : l) { // execTime.add(oh); // history.add(o); // i++; // } // return l; // } // // public List<Long> getExecTime() { // return execTime; // } // // public List<Operation> getHistory() { // return history; // } // // public TreeMap<Integer, Long> getLocalExecTime() { // return localExecTime; // } // // public List<TraceOperation> getLocalHistory() { // return localHistory; // } // // public Document getDoc() { // return doc; // } // // public void setDoc(Document doc) { // this.doc = doc; // } // // public void setReplicaNb(int replicaNb) { // this.replicaNb = replicaNb; // } // // public int getReplicaNb() { // return replicaNb; // } // // public void reset() { // this.execTime.clear(); // this.localExecTime.clear(); // this.history.clear(); // this.localHistory.clear(); // } // } // // Path: src/jbenchmarker/core/ReplicaFactory.java // public abstract class ReplicaFactory { // public abstract MergeAlgorithm createReplica(int r); // }
import jbenchmarker.core.MergeAlgorithm; import jbenchmarker.core.ReplicaFactory;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.rga; public class RGAFactory extends ReplicaFactory { @Override
// Path: src/jbenchmarker/core/MergeAlgorithm.java // public abstract class MergeAlgorithm { // // Replica identifier // private int replicaNb; // // // Supported Document // private Document doc; // // // Local operations generated // private List<TraceOperation> localHistory; // // // All operations executed // private List<Operation> history; // // // Local operations generated time map : size history -> exec time // private TreeMap<Integer, Long> localExecTime; // // // All operations executed // private List<Long> execTime; // // /* // * Constructor // */ // public MergeAlgorithm(Document doc, int r) { // this(); // this.replicaNb = r; // this.doc = doc; // } // // public MergeAlgorithm() { // this.execTime = new ArrayList<Long>(); // this.localExecTime = new TreeMap<Integer, Long>(); // this.history = new ArrayList<Operation>(); // this.localHistory = new ArrayList<TraceOperation>(); // } // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract void integrateLocal(Operation op) throws IncorrectTrace; // // /** // * To be define by the concrete merge algorithm // * Should call doc.apply // */ // protected abstract List<Operation> generateLocal(TraceOperation opt) throws IncorrectTrace; // // // // /* // * Integration of a remote operation // * Adds operation in history and execution time // */ // public void integrate(Operation op) throws IncorrectTrace { // long startTime = System.nanoTime(); // history.add(op); // integrateLocal(op); // execTime.add(System.nanoTime() - startTime); // } // // /** // * Generation of a local trace operation, returns a patch of operation // * Throws IncorrectTrace iff operation is not generable in the context. // **/ // public List<Operation> generate(TraceOperation opt) throws IncorrectTrace { // localHistory.add(opt); // long startTime = System.nanoTime(); // List<Operation> l = generateLocal(opt); // long t = System.nanoTime() - startTime, oh = t/l.size(); // int i = history.size(); // localExecTime.put(i,t); // for (Operation o : l) { // execTime.add(oh); // history.add(o); // i++; // } // return l; // } // // public List<Long> getExecTime() { // return execTime; // } // // public List<Operation> getHistory() { // return history; // } // // public TreeMap<Integer, Long> getLocalExecTime() { // return localExecTime; // } // // public List<TraceOperation> getLocalHistory() { // return localHistory; // } // // public Document getDoc() { // return doc; // } // // public void setDoc(Document doc) { // this.doc = doc; // } // // public void setReplicaNb(int replicaNb) { // this.replicaNb = replicaNb; // } // // public int getReplicaNb() { // return replicaNb; // } // // public void reset() { // this.execTime.clear(); // this.localExecTime.clear(); // this.history.clear(); // this.localHistory.clear(); // } // } // // Path: src/jbenchmarker/core/ReplicaFactory.java // public abstract class ReplicaFactory { // public abstract MergeAlgorithm createReplica(int r); // } // Path: src/jbenchmarker/rga/RGAFactory.java import jbenchmarker.core.MergeAlgorithm; import jbenchmarker.core.ReplicaFactory; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.rga; public class RGAFactory extends ReplicaFactory { @Override
public MergeAlgorithm createReplica(int r) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/logoot/LogootDocument.java
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // }
import jbenchmarker.trace.TraceOperation; import jbenchmarker.core.Document; import jbenchmarker.core.Operation; import java.lang.Integer; import java.util.*; import java.util.ArrayList; import java.util.Random;
idTable.add(End); document.add(' '); } @Override public String view() { StringBuilder s = new StringBuilder(); for (char c : document) s.append(c); return s.substring(1, s.length()-1); } int dicho(LogootIdentifier idToSearch) { int startIndex = 0, endIndex = idTable.size()-1, middleIndex; do { middleIndex = startIndex + (endIndex - startIndex) / 2; int c = idTable.get(middleIndex).compareTo(idToSearch); if (c == 0) { return middleIndex; } else if (c < 0) { startIndex = middleIndex + 1; } else { endIndex = middleIndex - 1; } } while (startIndex < endIndex); return (idTable.get(startIndex).compareTo(idToSearch) < 0) ? startIndex + 1 : startIndex; } @Override
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // Path: src/jbenchmarker/logoot/LogootDocument.java import jbenchmarker.trace.TraceOperation; import jbenchmarker.core.Document; import jbenchmarker.core.Operation; import java.lang.Integer; import java.util.*; import java.util.ArrayList; import java.util.Random; idTable.add(End); document.add(' '); } @Override public String view() { StringBuilder s = new StringBuilder(); for (char c : document) s.append(c); return s.substring(1, s.length()-1); } int dicho(LogootIdentifier idToSearch) { int startIndex = 0, endIndex = idTable.size()-1, middleIndex; do { middleIndex = startIndex + (endIndex - startIndex) / 2; int c = idTable.get(middleIndex).compareTo(idToSearch); if (c == 0) { return middleIndex; } else if (c < 0) { startIndex = middleIndex + 1; } else { endIndex = middleIndex - 1; } } while (startIndex < endIndex); return (idTable.get(startIndex).compareTo(idToSearch) < 0) ? startIndex + 1 : startIndex; } @Override
public void applyLocal(Operation op) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/logoot/LogootDocument.java
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // }
import jbenchmarker.trace.TraceOperation; import jbenchmarker.core.Document; import jbenchmarker.core.Operation; import java.lang.Integer; import java.util.*; import java.util.ArrayList; import java.util.Random;
StringBuilder s = new StringBuilder(); for (char c : document) s.append(c); return s.substring(1, s.length()-1); } int dicho(LogootIdentifier idToSearch) { int startIndex = 0, endIndex = idTable.size()-1, middleIndex; do { middleIndex = startIndex + (endIndex - startIndex) / 2; int c = idTable.get(middleIndex).compareTo(idToSearch); if (c == 0) { return middleIndex; } else if (c < 0) { startIndex = middleIndex + 1; } else { endIndex = middleIndex - 1; } } while (startIndex < endIndex); return (idTable.get(startIndex).compareTo(idToSearch) < 0) ? startIndex + 1 : startIndex; } @Override public void applyLocal(Operation op) { LogootOperation lg = (LogootOperation) op; LogootIdentifier idToSearch = lg.getIdentifiant(); int pos = dicho(idToSearch); //Insertion et Delete
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // Path: src/jbenchmarker/logoot/LogootDocument.java import jbenchmarker.trace.TraceOperation; import jbenchmarker.core.Document; import jbenchmarker.core.Operation; import java.lang.Integer; import java.util.*; import java.util.ArrayList; import java.util.Random; StringBuilder s = new StringBuilder(); for (char c : document) s.append(c); return s.substring(1, s.length()-1); } int dicho(LogootIdentifier idToSearch) { int startIndex = 0, endIndex = idTable.size()-1, middleIndex; do { middleIndex = startIndex + (endIndex - startIndex) / 2; int c = idTable.get(middleIndex).compareTo(idToSearch); if (c == 0) { return middleIndex; } else if (c < 0) { startIndex = middleIndex + 1; } else { endIndex = middleIndex - 1; } } while (startIndex < endIndex); return (idTable.get(startIndex).compareTo(idToSearch) < 0) ? startIndex + 1 : startIndex; } @Override public void applyLocal(Operation op) { LogootOperation lg = (LogootOperation) op; LogootIdentifier idToSearch = lg.getIdentifiant(); int pos = dicho(idToSearch); //Insertion et Delete
if (lg.getType() == TraceOperation.OpType.ins) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/woot/WootOperation.java
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del };
import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.woot; /** * * @author urso */ public class WootOperation extends Operation { private WootIdentifier id; private WootIdentifier ip; // previous private WootIdentifier in; // next private char content;
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del }; // Path: src/jbenchmarker/woot/WootOperation.java import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.woot; /** * * @author urso */ public class WootOperation extends Operation { private WootIdentifier id; private WootIdentifier ip; // previous private WootIdentifier in; // next private char content;
public WootOperation(TraceOperation o) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/woot/wooto/WootOptimizedNode.java
// Path: src/jbenchmarker/woot/WootIdentifier.java // public class WootIdentifier implements Comparable<WootIdentifier> { // public static final WootIdentifier IB = new WootIdentifier(-1,0); // public static final WootIdentifier IE = new WootIdentifier(-1,1);; // // public WootIdentifier(int replica, int clock) { // this.replica = replica; // this.clock = clock; // } // // private int replica; // private int clock; // // public int getClock() { // return clock; // } // // public int getReplica() { // return replica; // } // // // @Override // public int compareTo(WootIdentifier t) { // if (this.replica == t.replica) // return this.clock - t.clock; // else // return this.replica - t.replica; // } // // public WootIdentifier clone() { // return new WootIdentifier(replica,clock); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final WootIdentifier other = (WootIdentifier) obj; // if (this.replica != other.replica) { // return false; // } // if (this.clock != other.clock) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 13 * hash + this.replica; // hash = 13 * hash + this.clock; // return hash; // } // } // // Path: src/jbenchmarker/woot/WootNode.java // public abstract class WootNode { // // private WootIdentifier id; // own identifier // // private char content; // private boolean visible; // // public WootNode(WootIdentifier id, char content, boolean visible) { // this.id = id; // this.content = content; // this.visible = visible; // } // // public WootIdentifier getId() { // return id; // } // // public char getContent() { // return content; // } // // public boolean isVisible() { // return visible; // } // // public void setVisible(boolean visible) { // this.visible = visible; // } // }
import jbenchmarker.woot.WootIdentifier; import jbenchmarker.woot.WootNode;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.woot.wooto; /** * * @author urso */ public class WootOptimizedNode extends WootNode { private int degree;
// Path: src/jbenchmarker/woot/WootIdentifier.java // public class WootIdentifier implements Comparable<WootIdentifier> { // public static final WootIdentifier IB = new WootIdentifier(-1,0); // public static final WootIdentifier IE = new WootIdentifier(-1,1);; // // public WootIdentifier(int replica, int clock) { // this.replica = replica; // this.clock = clock; // } // // private int replica; // private int clock; // // public int getClock() { // return clock; // } // // public int getReplica() { // return replica; // } // // // @Override // public int compareTo(WootIdentifier t) { // if (this.replica == t.replica) // return this.clock - t.clock; // else // return this.replica - t.replica; // } // // public WootIdentifier clone() { // return new WootIdentifier(replica,clock); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final WootIdentifier other = (WootIdentifier) obj; // if (this.replica != other.replica) { // return false; // } // if (this.clock != other.clock) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 13 * hash + this.replica; // hash = 13 * hash + this.clock; // return hash; // } // } // // Path: src/jbenchmarker/woot/WootNode.java // public abstract class WootNode { // // private WootIdentifier id; // own identifier // // private char content; // private boolean visible; // // public WootNode(WootIdentifier id, char content, boolean visible) { // this.id = id; // this.content = content; // this.visible = visible; // } // // public WootIdentifier getId() { // return id; // } // // public char getContent() { // return content; // } // // public boolean isVisible() { // return visible; // } // // public void setVisible(boolean visible) { // this.visible = visible; // } // } // Path: src/jbenchmarker/woot/wooto/WootOptimizedNode.java import jbenchmarker.woot.WootIdentifier; import jbenchmarker.woot.WootNode; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.woot.wooto; /** * * @author urso */ public class WootOptimizedNode extends WootNode { private int degree;
public static final WootOptimizedNode CB = new WootOptimizedNode(WootIdentifier.IB, 0, ' ', false);
PascalUrso/ReplicationBenchmark
src/jbenchmarker/rga/RGAS4Vector.java
// Path: src/jbenchmarker/core/VectorClock.java // public class VectorClock extends TreeMap<Integer, Integer> { // // public VectorClock() { // super(); // } // // // TODO: test me, plz // public VectorClock(VectorClock siteVC) { // super(siteVC); // } // // /* // * Is this VC is ready to integrate O ? // * true iff VCr = Or - 1 && for all i!=r, VCi >= Oi // */ // public boolean readyFor(int r, VectorClock O) { // if (this.getSafe(r) != O.get(r) - 1) { // return false; // } // Iterator<Map.Entry<Integer, Integer>> it = O.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> e = it.next(); // if ((e.getKey() != r) && (this.getSafe(e.getKey()) < e.getValue())) { // return false; // } // } // return true; // } // // /** // * Get the sum of all entries // * added by Roh. // */ // public int getSum(){ // int sum = 0; // Iterator<Map.Entry<Integer, Integer>> it = this.entrySet().iterator(); // while (it.hasNext()) sum+= it.next().getValue(); // return sum; // } // // /* // * Increment an entry. // */ // public void inc(int r) { // put(r, getSafe(r) + 1); // } // // /* // * Returns the entry for replica r. 0 if none. // */ // public int getSafe(int r) { // Integer v = get(r); // return (v != null) ? v : 0; // } // // /* // * Is this VC > T ? // * true iff for all i, VCi >= Ti and exists j VCj > Tj // */ // public boolean greaterThan(VectorClock T) { // boolean gt = false; // Iterator<Map.Entry<Integer, Integer>> it = T.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (this.getSafe(i.getKey()) < i.getValue()) { // return false; // } else if (this.getSafe(i.getKey()) > i.getValue()) { // gt = true; // } // } // if (gt) { // return true; // } // it = this.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (T.getSafe(i.getKey()) < i.getValue()) { // return true; // } // } // return false; // } // // /* // * Is this VC // T ? // * true iff nor VC > T nor T > VC // */ // public boolean concurrent(VectorClock T) { // return !(this.greaterThan(T) || T.greaterThan(this)); // } // // /** // * Sets each entry of the VC to max(VCi, Oi) // */ // public void upTo(VectorClock O) { // for (Entry<Integer, Integer> k : O.entrySet()) { // if (k.getValue() > this.getSafe(k.getKey())) { // this.put(k.getKey(), k.getValue()); // } // } // } // // @Override // public boolean equals(Object obj) { // if (obj == null || getClass() != obj.getClass()) { // return false; // } // // final VectorClock other = (VectorClock) obj; // // Set<Integer> h = new HashSet<Integer>(this.keySet()); // h.addAll(other.keySet()); // // for (Integer k : h) { // if (this.getSafe(k) != other.getSafe(k)) { // return false; // } // } // return true; // } // // /* // * computes minimal vector from current and vector clocks provided in parameters. // * for each vc in {this} U otherVectorClocks, for each i in min, min[i] <= vc[i] // */ // public VectorClock min(Collection<VectorClock> otherVectorClocks) { // VectorClock min = new VectorClock(this); // // for (VectorClock clock : otherVectorClocks) { // Iterator<Map.Entry<Integer, Integer>> componentIterator = clock.entrySet().iterator(); // while (componentIterator.hasNext()) { // Map.Entry<Integer, Integer> i = componentIterator.next(); // Integer key = i.getKey(); // min.put(key, Math.min(min.getSafe(key), i.getValue())); // } // } // return min; // } // }
import jbenchmarker.core.VectorClock;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.rga; /** * * @author Roh */ public class RGAS4Vector implements Comparable<RGAS4Vector> { public static final int AFTER = 1; public static final int EQUAL = 0; public static final int BEFORE = -1; private int ssn; private int sid; private int sum; private int seq;
// Path: src/jbenchmarker/core/VectorClock.java // public class VectorClock extends TreeMap<Integer, Integer> { // // public VectorClock() { // super(); // } // // // TODO: test me, plz // public VectorClock(VectorClock siteVC) { // super(siteVC); // } // // /* // * Is this VC is ready to integrate O ? // * true iff VCr = Or - 1 && for all i!=r, VCi >= Oi // */ // public boolean readyFor(int r, VectorClock O) { // if (this.getSafe(r) != O.get(r) - 1) { // return false; // } // Iterator<Map.Entry<Integer, Integer>> it = O.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> e = it.next(); // if ((e.getKey() != r) && (this.getSafe(e.getKey()) < e.getValue())) { // return false; // } // } // return true; // } // // /** // * Get the sum of all entries // * added by Roh. // */ // public int getSum(){ // int sum = 0; // Iterator<Map.Entry<Integer, Integer>> it = this.entrySet().iterator(); // while (it.hasNext()) sum+= it.next().getValue(); // return sum; // } // // /* // * Increment an entry. // */ // public void inc(int r) { // put(r, getSafe(r) + 1); // } // // /* // * Returns the entry for replica r. 0 if none. // */ // public int getSafe(int r) { // Integer v = get(r); // return (v != null) ? v : 0; // } // // /* // * Is this VC > T ? // * true iff for all i, VCi >= Ti and exists j VCj > Tj // */ // public boolean greaterThan(VectorClock T) { // boolean gt = false; // Iterator<Map.Entry<Integer, Integer>> it = T.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (this.getSafe(i.getKey()) < i.getValue()) { // return false; // } else if (this.getSafe(i.getKey()) > i.getValue()) { // gt = true; // } // } // if (gt) { // return true; // } // it = this.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (T.getSafe(i.getKey()) < i.getValue()) { // return true; // } // } // return false; // } // // /* // * Is this VC // T ? // * true iff nor VC > T nor T > VC // */ // public boolean concurrent(VectorClock T) { // return !(this.greaterThan(T) || T.greaterThan(this)); // } // // /** // * Sets each entry of the VC to max(VCi, Oi) // */ // public void upTo(VectorClock O) { // for (Entry<Integer, Integer> k : O.entrySet()) { // if (k.getValue() > this.getSafe(k.getKey())) { // this.put(k.getKey(), k.getValue()); // } // } // } // // @Override // public boolean equals(Object obj) { // if (obj == null || getClass() != obj.getClass()) { // return false; // } // // final VectorClock other = (VectorClock) obj; // // Set<Integer> h = new HashSet<Integer>(this.keySet()); // h.addAll(other.keySet()); // // for (Integer k : h) { // if (this.getSafe(k) != other.getSafe(k)) { // return false; // } // } // return true; // } // // /* // * computes minimal vector from current and vector clocks provided in parameters. // * for each vc in {this} U otherVectorClocks, for each i in min, min[i] <= vc[i] // */ // public VectorClock min(Collection<VectorClock> otherVectorClocks) { // VectorClock min = new VectorClock(this); // // for (VectorClock clock : otherVectorClocks) { // Iterator<Map.Entry<Integer, Integer>> componentIterator = clock.entrySet().iterator(); // while (componentIterator.hasNext()) { // Map.Entry<Integer, Integer> i = componentIterator.next(); // Integer key = i.getKey(); // min.put(key, Math.min(min.getSafe(key), i.getValue())); // } // } // return min; // } // } // Path: src/jbenchmarker/rga/RGAS4Vector.java import jbenchmarker.core.VectorClock; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.rga; /** * * @author Roh */ public class RGAS4Vector implements Comparable<RGAS4Vector> { public static final int AFTER = 1; public static final int EQUAL = 0; public static final int BEFORE = -1; private int ssn; private int sid; private int sum; private int seq;
public RGAS4Vector(int ssn, int sid, VectorClock vc){
PascalUrso/ReplicationBenchmark
src/jbenchmarker/rga/RGAOperation.java
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del };
import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.rga; /** * * @author Roh */ public class RGAOperation extends Operation { public static boolean LOCAL = true; public static boolean REMOTE = false; private RGAS4Vector s4vpos; private RGAS4Vector s4vtms; private char content; private boolean lor; // to be local or remote private int intpos;
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del }; // Path: src/jbenchmarker/rga/RGAOperation.java import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.rga; /** * * @author Roh */ public class RGAOperation extends Operation { public static boolean LOCAL = true; public static boolean REMOTE = false; private RGAS4Vector s4vpos; private RGAS4Vector s4vtms; private char content; private boolean lor; // to be local or remote private int intpos;
public RGAOperation(TraceOperation o) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/rga/RGAOperation.java
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del };
import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.rga; /** * * @author Roh */ public class RGAOperation extends Operation { public static boolean LOCAL = true; public static boolean REMOTE = false; private RGAS4Vector s4vpos; private RGAS4Vector s4vtms; private char content; private boolean lor; // to be local or remote private int intpos; public RGAOperation(TraceOperation o) { super(o); lor = LOCAL; } public void setLocal(){ lor = LOCAL; } public void setRemote(){ lor = REMOTE; } public boolean getLoR(){ return lor; } public String toString(){ String ret =new String();
// Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public enum OpType { ins, del }; // Path: src/jbenchmarker/rga/RGAOperation.java import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; import jbenchmarker.trace.TraceOperation.OpType; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.rga; /** * * @author Roh */ public class RGAOperation extends Operation { public static boolean LOCAL = true; public static boolean REMOTE = false; private RGAS4Vector s4vpos; private RGAS4Vector s4vtms; private char content; private boolean lor; // to be local or remote private int intpos; public RGAOperation(TraceOperation o) { super(o); lor = LOCAL; } public void setLocal(){ lor = LOCAL; } public void setRemote(){ lor = REMOTE; } public boolean getLoR(){ return lor; } public String toString(){ String ret =new String();
if(getType()==TraceOperation.OpType.del) ret +="del(";
PascalUrso/ReplicationBenchmark
test/jbenchmarker/trace/TraceGeneratorTest.java
// Path: src/jbenchmarker/core/VectorClock.java // public class VectorClock extends TreeMap<Integer, Integer> { // // public VectorClock() { // super(); // } // // // TODO: test me, plz // public VectorClock(VectorClock siteVC) { // super(siteVC); // } // // /* // * Is this VC is ready to integrate O ? // * true iff VCr = Or - 1 && for all i!=r, VCi >= Oi // */ // public boolean readyFor(int r, VectorClock O) { // if (this.getSafe(r) != O.get(r) - 1) { // return false; // } // Iterator<Map.Entry<Integer, Integer>> it = O.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> e = it.next(); // if ((e.getKey() != r) && (this.getSafe(e.getKey()) < e.getValue())) { // return false; // } // } // return true; // } // // /** // * Get the sum of all entries // * added by Roh. // */ // public int getSum(){ // int sum = 0; // Iterator<Map.Entry<Integer, Integer>> it = this.entrySet().iterator(); // while (it.hasNext()) sum+= it.next().getValue(); // return sum; // } // // /* // * Increment an entry. // */ // public void inc(int r) { // put(r, getSafe(r) + 1); // } // // /* // * Returns the entry for replica r. 0 if none. // */ // public int getSafe(int r) { // Integer v = get(r); // return (v != null) ? v : 0; // } // // /* // * Is this VC > T ? // * true iff for all i, VCi >= Ti and exists j VCj > Tj // */ // public boolean greaterThan(VectorClock T) { // boolean gt = false; // Iterator<Map.Entry<Integer, Integer>> it = T.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (this.getSafe(i.getKey()) < i.getValue()) { // return false; // } else if (this.getSafe(i.getKey()) > i.getValue()) { // gt = true; // } // } // if (gt) { // return true; // } // it = this.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (T.getSafe(i.getKey()) < i.getValue()) { // return true; // } // } // return false; // } // // /* // * Is this VC // T ? // * true iff nor VC > T nor T > VC // */ // public boolean concurrent(VectorClock T) { // return !(this.greaterThan(T) || T.greaterThan(this)); // } // // /** // * Sets each entry of the VC to max(VCi, Oi) // */ // public void upTo(VectorClock O) { // for (Entry<Integer, Integer> k : O.entrySet()) { // if (k.getValue() > this.getSafe(k.getKey())) { // this.put(k.getKey(), k.getValue()); // } // } // } // // @Override // public boolean equals(Object obj) { // if (obj == null || getClass() != obj.getClass()) { // return false; // } // // final VectorClock other = (VectorClock) obj; // // Set<Integer> h = new HashSet<Integer>(this.keySet()); // h.addAll(other.keySet()); // // for (Integer k : h) { // if (this.getSafe(k) != other.getSafe(k)) { // return false; // } // } // return true; // } // // /* // * computes minimal vector from current and vector clocks provided in parameters. // * for each vc in {this} U otherVectorClocks, for each i in min, min[i] <= vc[i] // */ // public VectorClock min(Collection<VectorClock> otherVectorClocks) { // VectorClock min = new VectorClock(this); // // for (VectorClock clock : otherVectorClocks) { // Iterator<Map.Entry<Integer, Integer>> componentIterator = clock.entrySet().iterator(); // while (componentIterator.hasNext()) { // Map.Entry<Integer, Integer> i = componentIterator.next(); // Integer key = i.getKey(); // min.put(key, Math.min(min.getSafe(key), i.getValue())); // } // } // return min; // } // }
import java.util.List; import java.util.Map; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; import java.util.HashMap; import java.util.Iterator; import java.io.StringReader; import org.jdom.Document; import org.jdom.input.SAXBuilder; import jbenchmarker.core.VectorClock; import java.util.ArrayList;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.trace; /** * * @author urso */ public class TraceGeneratorTest { private static List<TraceOperation> it2list(Iterator<TraceOperation> t) { List<TraceOperation> l = new ArrayList<TraceOperation>(); while (t.hasNext()) l.add(t.next()); return l; } /** * Helper to construct a 3 entries VC */
// Path: src/jbenchmarker/core/VectorClock.java // public class VectorClock extends TreeMap<Integer, Integer> { // // public VectorClock() { // super(); // } // // // TODO: test me, plz // public VectorClock(VectorClock siteVC) { // super(siteVC); // } // // /* // * Is this VC is ready to integrate O ? // * true iff VCr = Or - 1 && for all i!=r, VCi >= Oi // */ // public boolean readyFor(int r, VectorClock O) { // if (this.getSafe(r) != O.get(r) - 1) { // return false; // } // Iterator<Map.Entry<Integer, Integer>> it = O.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> e = it.next(); // if ((e.getKey() != r) && (this.getSafe(e.getKey()) < e.getValue())) { // return false; // } // } // return true; // } // // /** // * Get the sum of all entries // * added by Roh. // */ // public int getSum(){ // int sum = 0; // Iterator<Map.Entry<Integer, Integer>> it = this.entrySet().iterator(); // while (it.hasNext()) sum+= it.next().getValue(); // return sum; // } // // /* // * Increment an entry. // */ // public void inc(int r) { // put(r, getSafe(r) + 1); // } // // /* // * Returns the entry for replica r. 0 if none. // */ // public int getSafe(int r) { // Integer v = get(r); // return (v != null) ? v : 0; // } // // /* // * Is this VC > T ? // * true iff for all i, VCi >= Ti and exists j VCj > Tj // */ // public boolean greaterThan(VectorClock T) { // boolean gt = false; // Iterator<Map.Entry<Integer, Integer>> it = T.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (this.getSafe(i.getKey()) < i.getValue()) { // return false; // } else if (this.getSafe(i.getKey()) > i.getValue()) { // gt = true; // } // } // if (gt) { // return true; // } // it = this.entrySet().iterator(); // while (it.hasNext()) { // Map.Entry<Integer, Integer> i = it.next(); // if (T.getSafe(i.getKey()) < i.getValue()) { // return true; // } // } // return false; // } // // /* // * Is this VC // T ? // * true iff nor VC > T nor T > VC // */ // public boolean concurrent(VectorClock T) { // return !(this.greaterThan(T) || T.greaterThan(this)); // } // // /** // * Sets each entry of the VC to max(VCi, Oi) // */ // public void upTo(VectorClock O) { // for (Entry<Integer, Integer> k : O.entrySet()) { // if (k.getValue() > this.getSafe(k.getKey())) { // this.put(k.getKey(), k.getValue()); // } // } // } // // @Override // public boolean equals(Object obj) { // if (obj == null || getClass() != obj.getClass()) { // return false; // } // // final VectorClock other = (VectorClock) obj; // // Set<Integer> h = new HashSet<Integer>(this.keySet()); // h.addAll(other.keySet()); // // for (Integer k : h) { // if (this.getSafe(k) != other.getSafe(k)) { // return false; // } // } // return true; // } // // /* // * computes minimal vector from current and vector clocks provided in parameters. // * for each vc in {this} U otherVectorClocks, for each i in min, min[i] <= vc[i] // */ // public VectorClock min(Collection<VectorClock> otherVectorClocks) { // VectorClock min = new VectorClock(this); // // for (VectorClock clock : otherVectorClocks) { // Iterator<Map.Entry<Integer, Integer>> componentIterator = clock.entrySet().iterator(); // while (componentIterator.hasNext()) { // Map.Entry<Integer, Integer> i = componentIterator.next(); // Integer key = i.getKey(); // min.put(key, Math.min(min.getSafe(key), i.getValue())); // } // } // return min; // } // } // Path: test/jbenchmarker/trace/TraceGeneratorTest.java import java.util.List; import java.util.Map; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; import java.util.HashMap; import java.util.Iterator; import java.io.StringReader; import org.jdom.Document; import org.jdom.input.SAXBuilder; import jbenchmarker.core.VectorClock; import java.util.ArrayList; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package jbenchmarker.trace; /** * * @author urso */ public class TraceGeneratorTest { private static List<TraceOperation> it2list(Iterator<TraceOperation> t) { List<TraceOperation> l = new ArrayList<TraceOperation>(); while (t.hasNext()) l.add(t.next()); return l; } /** * Helper to construct a 3 entries VC */
public static VectorClock vc(int a, int b, int c) {
PascalUrso/ReplicationBenchmark
src/jbenchmarker/ot/TTFDocument.java
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // }
import java.util.ArrayList; import java.util.List; import jbenchmarker.core.Document; import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation;
/** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.ot; /** * * @author oster */ public class TTFDocument extends Document { protected List<TTFChar> model; public TTFDocument() { this.model = new ArrayList<TTFChar>(); } @Override public String view() { StringBuilder sb = new StringBuilder(); for (TTFChar c : this.model) { if (c.isVisible()) { sb.append(c.getChar()); } } return sb.toString(); } @Override
// Path: src/jbenchmarker/core/Document.java // public abstract class Document { // // // public Document() { // } // // /* // * View of the document (without metadata) // */ // abstract public String view(); // // /** // * Applies an operation // */ // public void apply(Operation op) { // applyLocal(op); // } // // abstract protected void applyLocal(Operation op); // } // // Path: src/jbenchmarker/core/Operation.java // public abstract class Operation { // private TraceOperation originalOp; // Trace operation issuing this one // // public TraceOperation getOriginalOp() { // return originalOp; // } // // public void setOriginalOp(TraceOperation originalOp) { // this.originalOp = originalOp; // } // // public Operation(TraceOperation o) { // this.originalOp = o; // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Operation other = (Operation) obj; // if (this.originalOp != other.originalOp && (this.originalOp == null || !this.originalOp.equals(other.originalOp))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 3; // hash = 17 * hash + (this.originalOp != null ? this.originalOp.hashCode() : 0); // return hash; // } // // abstract public Operation clone(); // } // // Path: src/jbenchmarker/trace/TraceOperation.java // public class TraceOperation { // public enum OpType { ins, del }; // // private int replica; // replica number // private OpType type; // type of operation : insert or delete // private int position; // position in the document // private int offset; // length of a del // private String content; // content of an ins // private VectorClock VC; // Vector clock // // // public VectorClock getVC() { // return VC; // } // // public String getContent() { // return content; // } // // public int getOffset() { // return offset; // } // // public int getPosition() { // return position; // } // // // public int getReplica() { // return replica; // } // // // public OpType getType() { // return type; // } // // public TraceOperation(OpType type, int replica, int position, int offset, String content, VectorClock VC) { // this.type = type; // this.replica = replica; // this.position = position; // this.offset = offset; // this.content = content; // this.VC = VC; // } // // /* // * Construction of an insert operation // */ // static public TraceOperation insert(int replica, int position, String content, VectorClock VC) { // return new TraceOperation(OpType.ins, replica, position, 0, content, VC); // } // // /* // * Construction of an insert operation // */ // static public TraceOperation delete(int replica, int position, int offset, VectorClock VC) { // return new TraceOperation(OpType.del, replica, position, offset, null, VC); // } // // @Override // public boolean equals(Object obj) { // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final TraceOperation other = (TraceOperation) obj; // if (this.replica != other.replica) { // return false; // } // if (this.type != other.type) { // return false; // } // if (this.position != other.position) { // return false; // } // if (this.offset != other.offset) { // return false; // } // if ((this.content == null) ? (other.content != null) : !this.content.equals(other.content)) { // return false; // } // if (this.VC != other.VC && (this.VC == null || !this.VC.equals(other.VC))) { // return false; // } // return true; // } // // @Override // public int hashCode() { // int hash = 7; // hash = 53 * hash + this.replica; // hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0); // hash = 53 * hash + this.position; // hash = 53 * hash + this.offset; // hash = 53 * hash + (this.content != null ? this.content.hashCode() : 0); // hash = 53 * hash + (this.VC != null ? this.VC.hashCode() : 0); // return hash; // } // // @Override // public String toString() { // return "TraceOperation{" + "replica=" + replica + ", VC=" + VC + ", type=" + type + ", position=" + position + (type==OpType.del ? ", offset=" + offset : ", content=" + content) + '}'; // } // // // } // Path: src/jbenchmarker/ot/TTFDocument.java import java.util.ArrayList; import java.util.List; import jbenchmarker.core.Document; import jbenchmarker.core.Operation; import jbenchmarker.trace.TraceOperation; /** * This file is part of ReplicationBenchmark. * * ReplicationBenchmark is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ReplicationBenchmark is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ReplicationBenchmark. If not, see <http://www.gnu.org/licenses/>. * **/ package jbenchmarker.ot; /** * * @author oster */ public class TTFDocument extends Document { protected List<TTFChar> model; public TTFDocument() { this.model = new ArrayList<TTFChar>(); } @Override public String view() { StringBuilder sb = new StringBuilder(); for (TTFChar c : this.model) { if (c.isVisible()) { sb.append(c.getChar()); } } return sb.toString(); } @Override
public void applyLocal(Operation op) {
Valkryst/Schillsaver
src/main/java/Schillsaver/job/Job.java
// Path: src/main/java/Schillsaver/job/archive/Archiver.java // public abstract class Archiver { // /** // * Packs one or more files into an archive. // * // * @param fileName // * The archive file name. // * // * @param files // * The files. // * // * @return // * The archive file. // * // * @throws IllegalArgumentException // * If an I/O error occurs. // */ // public abstract File archive(final @NonNull String fileName, final List<File> files) throws IOException; // // /** // * Pads the specified file to ensure it contains enough data to have an exact number of frames. // * // * If there are, for example, 1401 bytes and the frame size is 1400 bytes, then FFMPEG will display an // * error about not having a full frame worth of bytes. // * // * @param file // * The file. // * // * @throws NullPointerException // * If the file or settings is null. // */ // protected File padFile(final @NonNull File file) { // final Settings settings = Settings.getInstance(); // // try (final FileOutputStream outputStream = new FileOutputStream(file, true)) { // final FrameDimension frameDimension = FrameDimension.valueOf(settings.getStringSetting("Encoding Frame Dimensions")); // final int blockSize = BlockSize.valueOf(settings.getStringSetting("Encoding Block Size")).getBlockSize(); // // int bytesPerFrame = frameDimension.getWidth() * frameDimension.getHeight(); // bytesPerFrame /= blockSize * blockSize; // bytesPerFrame /= 8; // // final int numberOfBytesToPad = bytesPerFrame - (int) (file.length() % bytesPerFrame); // // outputStream.write(new byte[numberOfBytesToPad]); // } catch (final IOException e) { // e.printStackTrace(); // } // // return file; // } // // /** // * Retrieves the file name, appended with the archive extension. // * // * @return // * The file name, appended with the archive extension. // */ // public abstract String getFileName(final String fileName); // } // // Path: src/main/java/Schillsaver/job/archive/ArchiverFactory.java // public class ArchiverFactory { // /** The cache of created archivers. */ // private final static HashMap<ArchiveType, Archiver> CACHE = new HashMap<>(); // // // Ensure no instance of the factory can be created. // private ArchiverFactory() {} // // /** // * Creates a new archiver. // * // * @param type // * The type. // * // * @return // * The archiver. // * // * @throws NullPointerException // * If the type is null. // */ // public static Archiver create(final @NonNull ArchiveType type) { // if (CACHE.containsKey(type)) { // return CACHE.get(type); // } // // switch (type) { // case ZIP: { // final ZipArchiver archiver = new ZipArchiver(); // CACHE.put(type, archiver); // return archiver; // } // default: { // throw new UnsupportedOperationException("The '" + type.name() + "' archiver is not supported."); // } // } // } // }
import Schillsaver.job.archive.Archiver; import Schillsaver.job.archive.ArchiverFactory; import lombok.Getter; import lombok.NonNull; import java.io.*; import java.util.List;
package Schillsaver.job; public class Job implements Serializable { private static final long serialVersionUID = 1; /** The name of the Job. */ @Getter private final String name; /** The output directory. */ @Getter private final String outputDirectory; /** The archiver used to archive the file(s). */
// Path: src/main/java/Schillsaver/job/archive/Archiver.java // public abstract class Archiver { // /** // * Packs one or more files into an archive. // * // * @param fileName // * The archive file name. // * // * @param files // * The files. // * // * @return // * The archive file. // * // * @throws IllegalArgumentException // * If an I/O error occurs. // */ // public abstract File archive(final @NonNull String fileName, final List<File> files) throws IOException; // // /** // * Pads the specified file to ensure it contains enough data to have an exact number of frames. // * // * If there are, for example, 1401 bytes and the frame size is 1400 bytes, then FFMPEG will display an // * error about not having a full frame worth of bytes. // * // * @param file // * The file. // * // * @throws NullPointerException // * If the file or settings is null. // */ // protected File padFile(final @NonNull File file) { // final Settings settings = Settings.getInstance(); // // try (final FileOutputStream outputStream = new FileOutputStream(file, true)) { // final FrameDimension frameDimension = FrameDimension.valueOf(settings.getStringSetting("Encoding Frame Dimensions")); // final int blockSize = BlockSize.valueOf(settings.getStringSetting("Encoding Block Size")).getBlockSize(); // // int bytesPerFrame = frameDimension.getWidth() * frameDimension.getHeight(); // bytesPerFrame /= blockSize * blockSize; // bytesPerFrame /= 8; // // final int numberOfBytesToPad = bytesPerFrame - (int) (file.length() % bytesPerFrame); // // outputStream.write(new byte[numberOfBytesToPad]); // } catch (final IOException e) { // e.printStackTrace(); // } // // return file; // } // // /** // * Retrieves the file name, appended with the archive extension. // * // * @return // * The file name, appended with the archive extension. // */ // public abstract String getFileName(final String fileName); // } // // Path: src/main/java/Schillsaver/job/archive/ArchiverFactory.java // public class ArchiverFactory { // /** The cache of created archivers. */ // private final static HashMap<ArchiveType, Archiver> CACHE = new HashMap<>(); // // // Ensure no instance of the factory can be created. // private ArchiverFactory() {} // // /** // * Creates a new archiver. // * // * @param type // * The type. // * // * @return // * The archiver. // * // * @throws NullPointerException // * If the type is null. // */ // public static Archiver create(final @NonNull ArchiveType type) { // if (CACHE.containsKey(type)) { // return CACHE.get(type); // } // // switch (type) { // case ZIP: { // final ZipArchiver archiver = new ZipArchiver(); // CACHE.put(type, archiver); // return archiver; // } // default: { // throw new UnsupportedOperationException("The '" + type.name() + "' archiver is not supported."); // } // } // } // } // Path: src/main/java/Schillsaver/job/Job.java import Schillsaver.job.archive.Archiver; import Schillsaver.job.archive.ArchiverFactory; import lombok.Getter; import lombok.NonNull; import java.io.*; import java.util.List; package Schillsaver.job; public class Job implements Serializable { private static final long serialVersionUID = 1; /** The name of the Job. */ @Getter private final String name; /** The output directory. */ @Getter private final String outputDirectory; /** The archiver used to archive the file(s). */
@Getter private final Archiver archiver;
Valkryst/Schillsaver
src/main/java/Schillsaver/job/Job.java
// Path: src/main/java/Schillsaver/job/archive/Archiver.java // public abstract class Archiver { // /** // * Packs one or more files into an archive. // * // * @param fileName // * The archive file name. // * // * @param files // * The files. // * // * @return // * The archive file. // * // * @throws IllegalArgumentException // * If an I/O error occurs. // */ // public abstract File archive(final @NonNull String fileName, final List<File> files) throws IOException; // // /** // * Pads the specified file to ensure it contains enough data to have an exact number of frames. // * // * If there are, for example, 1401 bytes and the frame size is 1400 bytes, then FFMPEG will display an // * error about not having a full frame worth of bytes. // * // * @param file // * The file. // * // * @throws NullPointerException // * If the file or settings is null. // */ // protected File padFile(final @NonNull File file) { // final Settings settings = Settings.getInstance(); // // try (final FileOutputStream outputStream = new FileOutputStream(file, true)) { // final FrameDimension frameDimension = FrameDimension.valueOf(settings.getStringSetting("Encoding Frame Dimensions")); // final int blockSize = BlockSize.valueOf(settings.getStringSetting("Encoding Block Size")).getBlockSize(); // // int bytesPerFrame = frameDimension.getWidth() * frameDimension.getHeight(); // bytesPerFrame /= blockSize * blockSize; // bytesPerFrame /= 8; // // final int numberOfBytesToPad = bytesPerFrame - (int) (file.length() % bytesPerFrame); // // outputStream.write(new byte[numberOfBytesToPad]); // } catch (final IOException e) { // e.printStackTrace(); // } // // return file; // } // // /** // * Retrieves the file name, appended with the archive extension. // * // * @return // * The file name, appended with the archive extension. // */ // public abstract String getFileName(final String fileName); // } // // Path: src/main/java/Schillsaver/job/archive/ArchiverFactory.java // public class ArchiverFactory { // /** The cache of created archivers. */ // private final static HashMap<ArchiveType, Archiver> CACHE = new HashMap<>(); // // // Ensure no instance of the factory can be created. // private ArchiverFactory() {} // // /** // * Creates a new archiver. // * // * @param type // * The type. // * // * @return // * The archiver. // * // * @throws NullPointerException // * If the type is null. // */ // public static Archiver create(final @NonNull ArchiveType type) { // if (CACHE.containsKey(type)) { // return CACHE.get(type); // } // // switch (type) { // case ZIP: { // final ZipArchiver archiver = new ZipArchiver(); // CACHE.put(type, archiver); // return archiver; // } // default: { // throw new UnsupportedOperationException("The '" + type.name() + "' archiver is not supported."); // } // } // } // }
import Schillsaver.job.archive.Archiver; import Schillsaver.job.archive.ArchiverFactory; import lombok.Getter; import lombok.NonNull; import java.io.*; import java.util.List;
package Schillsaver.job; public class Job implements Serializable { private static final long serialVersionUID = 1; /** The name of the Job. */ @Getter private final String name; /** The output directory. */ @Getter private final String outputDirectory; /** The archiver used to archive the file(s). */ @Getter private final Archiver archiver; /** The file(s) to process.*/ @Getter private final List<File> files; /** Whether the Job is an Encode Job or a Decode Job. */ @Getter private final boolean isEncodeJob; /** * Constructs a new Job. * * @param builder * The builder * * @throws NullPointerException * If the builder is null. */ Job(final @NonNull JobBuilder builder) { name = builder.getName(); outputDirectory = builder.getOutputDirectory();
// Path: src/main/java/Schillsaver/job/archive/Archiver.java // public abstract class Archiver { // /** // * Packs one or more files into an archive. // * // * @param fileName // * The archive file name. // * // * @param files // * The files. // * // * @return // * The archive file. // * // * @throws IllegalArgumentException // * If an I/O error occurs. // */ // public abstract File archive(final @NonNull String fileName, final List<File> files) throws IOException; // // /** // * Pads the specified file to ensure it contains enough data to have an exact number of frames. // * // * If there are, for example, 1401 bytes and the frame size is 1400 bytes, then FFMPEG will display an // * error about not having a full frame worth of bytes. // * // * @param file // * The file. // * // * @throws NullPointerException // * If the file or settings is null. // */ // protected File padFile(final @NonNull File file) { // final Settings settings = Settings.getInstance(); // // try (final FileOutputStream outputStream = new FileOutputStream(file, true)) { // final FrameDimension frameDimension = FrameDimension.valueOf(settings.getStringSetting("Encoding Frame Dimensions")); // final int blockSize = BlockSize.valueOf(settings.getStringSetting("Encoding Block Size")).getBlockSize(); // // int bytesPerFrame = frameDimension.getWidth() * frameDimension.getHeight(); // bytesPerFrame /= blockSize * blockSize; // bytesPerFrame /= 8; // // final int numberOfBytesToPad = bytesPerFrame - (int) (file.length() % bytesPerFrame); // // outputStream.write(new byte[numberOfBytesToPad]); // } catch (final IOException e) { // e.printStackTrace(); // } // // return file; // } // // /** // * Retrieves the file name, appended with the archive extension. // * // * @return // * The file name, appended with the archive extension. // */ // public abstract String getFileName(final String fileName); // } // // Path: src/main/java/Schillsaver/job/archive/ArchiverFactory.java // public class ArchiverFactory { // /** The cache of created archivers. */ // private final static HashMap<ArchiveType, Archiver> CACHE = new HashMap<>(); // // // Ensure no instance of the factory can be created. // private ArchiverFactory() {} // // /** // * Creates a new archiver. // * // * @param type // * The type. // * // * @return // * The archiver. // * // * @throws NullPointerException // * If the type is null. // */ // public static Archiver create(final @NonNull ArchiveType type) { // if (CACHE.containsKey(type)) { // return CACHE.get(type); // } // // switch (type) { // case ZIP: { // final ZipArchiver archiver = new ZipArchiver(); // CACHE.put(type, archiver); // return archiver; // } // default: { // throw new UnsupportedOperationException("The '" + type.name() + "' archiver is not supported."); // } // } // } // } // Path: src/main/java/Schillsaver/job/Job.java import Schillsaver.job.archive.Archiver; import Schillsaver.job.archive.ArchiverFactory; import lombok.Getter; import lombok.NonNull; import java.io.*; import java.util.List; package Schillsaver.job; public class Job implements Serializable { private static final long serialVersionUID = 1; /** The name of the Job. */ @Getter private final String name; /** The output directory. */ @Getter private final String outputDirectory; /** The archiver used to archive the file(s). */ @Getter private final Archiver archiver; /** The file(s) to process.*/ @Getter private final List<File> files; /** Whether the Job is an Encode Job or a Decode Job. */ @Getter private final boolean isEncodeJob; /** * Constructs a new Job. * * @param builder * The builder * * @throws NullPointerException * If the builder is null. */ Job(final @NonNull JobBuilder builder) { name = builder.getName(); outputDirectory = builder.getOutputDirectory();
archiver = ArchiverFactory.create(builder.getArchiveType());
palo-m/androboinc
AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/ClientBridge.java
// Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/AutoRefresh.java // public enum RequestType { // CLIENT_MODE, // PROJECTS, // TASKS, // TRANSFERS, // MESSAGES // } // // Path: BoincRpc/src/main/java/edu/berkeley/boinc/NetStats.java // public interface NetStats { // public abstract void connectionOpened(); // public abstract void bytesReceived(int numBytes); // public abstract void bytesTransferred(int numBytes); // public abstract void connectionClosed(); // }
import sk.boinc.androboinc.BuildConfig; import sk.boinc.androboinc.bridge.AutoRefresh.RequestType; import sk.boinc.androboinc.clientconnection.ClientReplyReceiver; import sk.boinc.androboinc.clientconnection.ClientRequestHandler; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.DisconnectCause; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.ProgressInd; import sk.boinc.androboinc.clientconnection.HostInfo; import sk.boinc.androboinc.clientconnection.MessageInfo; import sk.boinc.androboinc.clientconnection.ModeInfo; import sk.boinc.androboinc.clientconnection.ProjectInfo; import sk.boinc.androboinc.clientconnection.TaskInfo; import sk.boinc.androboinc.clientconnection.TransferInfo; import sk.boinc.androboinc.clientconnection.VersionInfo; import edu.berkeley.boinc.NetStats; import sk.boinc.androboinc.util.ClientId; import android.content.Context; import android.os.ConditionVariable; import android.util.Log; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.Vector;
} } public void notifyDisconnected() { mConnected = false; Iterator<ClientReplyReceiver> it = mReceivers.iterator(); while (it.hasNext()) { ClientReplyReceiver receiver = it.next(); receiver.clientDisconnected(); if (BuildConfig.DEBUG) Log.d(TAG, "Detached receiver: " + receiver.toString()); // see below clearing of all receivers } mReceivers.clear(); } public void updatedClientMode(final ClientReplyReceiver callback, final ModeInfo modeInfo) { if (callback == null) { // No specific callback - broadcast to all receivers // This is used for early notification after connect Iterator<ClientReplyReceiver> it = mReceivers.iterator(); while (it.hasNext()) { ClientReplyReceiver receiver = it.next(); receiver.updatedClientMode(modeInfo); } return; } // Check whether callback is still present in receivers if (mReceivers.contains(callback)) { // Observer is still present, so we can call it back with data boolean periodicAllowed = callback.updatedClientMode(modeInfo); if (periodicAllowed) {
// Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/AutoRefresh.java // public enum RequestType { // CLIENT_MODE, // PROJECTS, // TASKS, // TRANSFERS, // MESSAGES // } // // Path: BoincRpc/src/main/java/edu/berkeley/boinc/NetStats.java // public interface NetStats { // public abstract void connectionOpened(); // public abstract void bytesReceived(int numBytes); // public abstract void bytesTransferred(int numBytes); // public abstract void connectionClosed(); // } // Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/ClientBridge.java import sk.boinc.androboinc.BuildConfig; import sk.boinc.androboinc.bridge.AutoRefresh.RequestType; import sk.boinc.androboinc.clientconnection.ClientReplyReceiver; import sk.boinc.androboinc.clientconnection.ClientRequestHandler; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.DisconnectCause; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.ProgressInd; import sk.boinc.androboinc.clientconnection.HostInfo; import sk.boinc.androboinc.clientconnection.MessageInfo; import sk.boinc.androboinc.clientconnection.ModeInfo; import sk.boinc.androboinc.clientconnection.ProjectInfo; import sk.boinc.androboinc.clientconnection.TaskInfo; import sk.boinc.androboinc.clientconnection.TransferInfo; import sk.boinc.androboinc.clientconnection.VersionInfo; import edu.berkeley.boinc.NetStats; import sk.boinc.androboinc.util.ClientId; import android.content.Context; import android.os.ConditionVariable; import android.util.Log; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.Vector; } } public void notifyDisconnected() { mConnected = false; Iterator<ClientReplyReceiver> it = mReceivers.iterator(); while (it.hasNext()) { ClientReplyReceiver receiver = it.next(); receiver.clientDisconnected(); if (BuildConfig.DEBUG) Log.d(TAG, "Detached receiver: " + receiver.toString()); // see below clearing of all receivers } mReceivers.clear(); } public void updatedClientMode(final ClientReplyReceiver callback, final ModeInfo modeInfo) { if (callback == null) { // No specific callback - broadcast to all receivers // This is used for early notification after connect Iterator<ClientReplyReceiver> it = mReceivers.iterator(); while (it.hasNext()) { ClientReplyReceiver receiver = it.next(); receiver.updatedClientMode(modeInfo); } return; } // Check whether callback is still present in receivers if (mReceivers.contains(callback)) { // Observer is still present, so we can call it back with data boolean periodicAllowed = callback.updatedClientMode(modeInfo); if (periodicAllowed) {
mAutoRefresh.scheduleAutomaticRefresh(callback, RequestType.CLIENT_MODE);
palo-m/androboinc
AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/ClientBridge.java
// Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/AutoRefresh.java // public enum RequestType { // CLIENT_MODE, // PROJECTS, // TASKS, // TRANSFERS, // MESSAGES // } // // Path: BoincRpc/src/main/java/edu/berkeley/boinc/NetStats.java // public interface NetStats { // public abstract void connectionOpened(); // public abstract void bytesReceived(int numBytes); // public abstract void bytesTransferred(int numBytes); // public abstract void connectionClosed(); // }
import sk.boinc.androboinc.BuildConfig; import sk.boinc.androboinc.bridge.AutoRefresh.RequestType; import sk.boinc.androboinc.clientconnection.ClientReplyReceiver; import sk.boinc.androboinc.clientconnection.ClientRequestHandler; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.DisconnectCause; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.ProgressInd; import sk.boinc.androboinc.clientconnection.HostInfo; import sk.boinc.androboinc.clientconnection.MessageInfo; import sk.boinc.androboinc.clientconnection.ModeInfo; import sk.boinc.androboinc.clientconnection.ProjectInfo; import sk.boinc.androboinc.clientconnection.TaskInfo; import sk.boinc.androboinc.clientconnection.TransferInfo; import sk.boinc.androboinc.clientconnection.VersionInfo; import edu.berkeley.boinc.NetStats; import sk.boinc.androboinc.util.ClientId; import android.content.Context; import android.os.ConditionVariable; import android.util.Log; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.Vector;
return; } // Check whether callback is still present in receivers if (mReceivers.contains(callback)) { // Yes, receiver is still present, so we can call it back with data boolean periodicAllowed = callback.updatedMessages(messages); if (periodicAllowed) { mAutoRefresh.scheduleAutomaticRefresh(callback, RequestType.MESSAGES); } } } } private final BridgeReply mBridgeReply = new BridgeReply(); private Set<ClientReplyReceiver> mReceivers = new HashSet<ClientReplyReceiver>(); private boolean mConnected = false; private ClientBridgeCallback mCallback; private ClientBridgeWorkerThread mWorker; private ClientId mRemoteClient = null; private final AutoRefresh mAutoRefresh; /** * Constructs a new <code>ClientBridge</code> and starts worker thread * * @throws RuntimeException if worker thread cannot start in a timely fashion */
// Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/AutoRefresh.java // public enum RequestType { // CLIENT_MODE, // PROJECTS, // TASKS, // TRANSFERS, // MESSAGES // } // // Path: BoincRpc/src/main/java/edu/berkeley/boinc/NetStats.java // public interface NetStats { // public abstract void connectionOpened(); // public abstract void bytesReceived(int numBytes); // public abstract void bytesTransferred(int numBytes); // public abstract void connectionClosed(); // } // Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/ClientBridge.java import sk.boinc.androboinc.BuildConfig; import sk.boinc.androboinc.bridge.AutoRefresh.RequestType; import sk.boinc.androboinc.clientconnection.ClientReplyReceiver; import sk.boinc.androboinc.clientconnection.ClientRequestHandler; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.DisconnectCause; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.ProgressInd; import sk.boinc.androboinc.clientconnection.HostInfo; import sk.boinc.androboinc.clientconnection.MessageInfo; import sk.boinc.androboinc.clientconnection.ModeInfo; import sk.boinc.androboinc.clientconnection.ProjectInfo; import sk.boinc.androboinc.clientconnection.TaskInfo; import sk.boinc.androboinc.clientconnection.TransferInfo; import sk.boinc.androboinc.clientconnection.VersionInfo; import edu.berkeley.boinc.NetStats; import sk.boinc.androboinc.util.ClientId; import android.content.Context; import android.os.ConditionVariable; import android.util.Log; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.Vector; return; } // Check whether callback is still present in receivers if (mReceivers.contains(callback)) { // Yes, receiver is still present, so we can call it back with data boolean periodicAllowed = callback.updatedMessages(messages); if (periodicAllowed) { mAutoRefresh.scheduleAutomaticRefresh(callback, RequestType.MESSAGES); } } } } private final BridgeReply mBridgeReply = new BridgeReply(); private Set<ClientReplyReceiver> mReceivers = new HashSet<ClientReplyReceiver>(); private boolean mConnected = false; private ClientBridgeCallback mCallback; private ClientBridgeWorkerThread mWorker; private ClientId mRemoteClient = null; private final AutoRefresh mAutoRefresh; /** * Constructs a new <code>ClientBridge</code> and starts worker thread * * @throws RuntimeException if worker thread cannot start in a timely fashion */
public ClientBridge(ClientBridgeCallback callback, Context context, NetStats netStats) throws RuntimeException {
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/CcStatusParserTest.java
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // }
import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class CcStatusParserTest { @Test public void parseNormal() {
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/CcStatusParserTest.java import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class CcStatusParserTest { @Test public void parseNormal() {
final String received = TestSupport.readResource(edu.berkeley.boinc.test.R.raw.get_cc_status_reply);
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/CcStateParserTest.java
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // }
import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.MediumTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @MediumTest public class CcStateParserTest { @Test public void parseNormal() {
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/CcStateParserTest.java import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.MediumTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @MediumTest public class CcStateParserTest { @Test public void parseNormal() {
final String received = TestSupport.readResource(edu.berkeley.boinc.test.R.raw.get_state_reply);
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/ResultsParserTest.java
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // }
import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import java.util.Vector; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class ResultsParserTest { @Test public void parseNormal() {
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/ResultsParserTest.java import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import java.util.Vector; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class ResultsParserTest { @Test public void parseNormal() {
final String received = TestSupport.readResource(edu.berkeley.boinc.test.R.raw.get_results_reply);
palo-m/androboinc
AndroBOINC/src/main/java/sk/boinc/androboinc/AppPreferencesActivity.java
// Path: AndroBOINC/src/main/java/sk/boinc/androboinc/util/ScreenOrientationHandler.java // public class ScreenOrientationHandler implements OnSharedPreferenceChangeListener { // private static final String TAG = "ScreenOrientationHandle"; // // private final Activity mActivity; // private int mChosenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; // // public ScreenOrientationHandler(Activity activity) { // mActivity = activity; // SharedPreferences globalPrefs = PreferenceManager.getDefaultSharedPreferences(mActivity); // globalPrefs.registerOnSharedPreferenceChangeListener(this); // String orientation = globalPrefs.getString(PreferenceName.SCREEN_ORIENTATION, "-1"); // int savedOrientation = Integer.parseInt(orientation); // if ( (savedOrientation < ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || // (savedOrientation > ActivityInfo.SCREEN_ORIENTATION_SENSOR) ) { // savedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; // } // mChosenOrientation = savedOrientation; // } // // @Override // public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // if (key.equals(PreferenceName.SCREEN_ORIENTATION)) { // String orientation = sharedPreferences.getString(PreferenceName.SCREEN_ORIENTATION, "-1"); // int newOrientation = Integer.parseInt(orientation); // if ( (newOrientation < ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || // (newOrientation > ActivityInfo.SCREEN_ORIENTATION_SENSOR) ) { // return; // } // if (newOrientation == mChosenOrientation) return; // unchanged // if (BuildConfig.DEBUG) Log.d(TAG, "Orientation setting changed from " + mChosenOrientation + " to " + newOrientation); // mChosenOrientation = newOrientation; // } // } // // public void setOrientation() { // if (mChosenOrientation != mActivity.getRequestedOrientation()) { // if (BuildConfig.DEBUG) Log.d(TAG, "Changing orientation for " + mActivity.toString()); // // mChosenOrientation can have only allowed values (see above) // //noinspection AndroidLintWrongConstant // mActivity.setRequestedOrientation(mChosenOrientation); // } // } // }
import sk.boinc.androboinc.util.NetStatsStorage; import sk.boinc.androboinc.util.PreferenceName; import sk.boinc.androboinc.util.ScreenOrientationHandler; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.CheckBox; import android.widget.TextView;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package sk.boinc.androboinc; public class AppPreferencesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { private static final String TAG = "AppPreferencesActivity"; private static final int DIALOG_NETSTATS_DISCLAIMER = 1; private static final int DIALOG_ABOUT = 2; private static final int DIALOG_LICENSE = 3; private static final int DIALOG_LICENSE2 = 4; private static final int DIALOG_CHANGELOG = 5; private BoincManagerApplication mApp;
// Path: AndroBOINC/src/main/java/sk/boinc/androboinc/util/ScreenOrientationHandler.java // public class ScreenOrientationHandler implements OnSharedPreferenceChangeListener { // private static final String TAG = "ScreenOrientationHandle"; // // private final Activity mActivity; // private int mChosenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; // // public ScreenOrientationHandler(Activity activity) { // mActivity = activity; // SharedPreferences globalPrefs = PreferenceManager.getDefaultSharedPreferences(mActivity); // globalPrefs.registerOnSharedPreferenceChangeListener(this); // String orientation = globalPrefs.getString(PreferenceName.SCREEN_ORIENTATION, "-1"); // int savedOrientation = Integer.parseInt(orientation); // if ( (savedOrientation < ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || // (savedOrientation > ActivityInfo.SCREEN_ORIENTATION_SENSOR) ) { // savedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; // } // mChosenOrientation = savedOrientation; // } // // @Override // public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // if (key.equals(PreferenceName.SCREEN_ORIENTATION)) { // String orientation = sharedPreferences.getString(PreferenceName.SCREEN_ORIENTATION, "-1"); // int newOrientation = Integer.parseInt(orientation); // if ( (newOrientation < ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || // (newOrientation > ActivityInfo.SCREEN_ORIENTATION_SENSOR) ) { // return; // } // if (newOrientation == mChosenOrientation) return; // unchanged // if (BuildConfig.DEBUG) Log.d(TAG, "Orientation setting changed from " + mChosenOrientation + " to " + newOrientation); // mChosenOrientation = newOrientation; // } // } // // public void setOrientation() { // if (mChosenOrientation != mActivity.getRequestedOrientation()) { // if (BuildConfig.DEBUG) Log.d(TAG, "Changing orientation for " + mActivity.toString()); // // mChosenOrientation can have only allowed values (see above) // //noinspection AndroidLintWrongConstant // mActivity.setRequestedOrientation(mChosenOrientation); // } // } // } // Path: AndroBOINC/src/main/java/sk/boinc/androboinc/AppPreferencesActivity.java import sk.boinc.androboinc.util.NetStatsStorage; import sk.boinc.androboinc.util.PreferenceName; import sk.boinc.androboinc.util.ScreenOrientationHandler; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.CheckBox; import android.widget.TextView; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package sk.boinc.androboinc; public class AppPreferencesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { private static final String TAG = "AppPreferencesActivity"; private static final int DIALOG_NETSTATS_DISCLAIMER = 1; private static final int DIALOG_ABOUT = 2; private static final int DIALOG_LICENSE = 3; private static final int DIALOG_LICENSE2 = 4; private static final int DIALOG_CHANGELOG = 5; private BoincManagerApplication mApp;
private ScreenOrientationHandler mScreenOrientation;
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/MessagesParserTest.java
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // }
import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import java.util.Vector; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class MessagesParserTest { @Test public void parseNormal() {
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/MessagesParserTest.java import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import java.util.Vector; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class MessagesParserTest { @Test public void parseNormal() {
final String received = TestSupport.readResource(edu.berkeley.boinc.test.R.raw.get_messages_reply);
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/TransfersParserTest.java
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // }
import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import java.util.Vector; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class TransfersParserTest { @Test public void parseNormal() {
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/TransfersParserTest.java import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import java.util.Vector; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class TransfersParserTest { @Test public void parseNormal() {
final String received = TestSupport.readResource(edu.berkeley.boinc.test.R.raw.get_file_transfers_reply);
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStubWorker.java
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/Md5.java // public class Md5 { // public static final String TAG = "Md5"; // // /** // * Hashes the input string // * // * @param text The text to be hashed // * @return The hash of the input converted to string // */ // public final static String hash(String text) { // try { // MessageDigest md5 = MessageDigest.getInstance("MD5"); // md5.update(text.getBytes("iso-8859-1"), 0, text.length()); // byte[] md5hash = md5.digest(); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i < md5hash.length; ++i) { // sb.append(String.format("%02x", md5hash[i])); // } // return sb.toString(); // } // catch (Exception e) { // Log.w(TAG, "Error when calculating MD5 hash"); // return ""; // } // } // } // // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStub.java // public enum Behavior { // DEFAULT, // NO_REPLY, // FAILURE, // TRUNCATED_DATA // }
import edu.berkeley.boinc.Md5; import edu.berkeley.boinc.testutil.BoincClientStub.Behavior; import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc.testutil; public class BoincClientStubWorker { private static final String TAG = "BoincClientStubWorker"; private static final int READ_BUF_SIZE = 8192; private Socket mSocket; private PrintWriter mOutput; private BufferedReader mInput; private StringBuilder mStringBuilder = new StringBuilder(); private boolean mProcessing = false;
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/Md5.java // public class Md5 { // public static final String TAG = "Md5"; // // /** // * Hashes the input string // * // * @param text The text to be hashed // * @return The hash of the input converted to string // */ // public final static String hash(String text) { // try { // MessageDigest md5 = MessageDigest.getInstance("MD5"); // md5.update(text.getBytes("iso-8859-1"), 0, text.length()); // byte[] md5hash = md5.digest(); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i < md5hash.length; ++i) { // sb.append(String.format("%02x", md5hash[i])); // } // return sb.toString(); // } // catch (Exception e) { // Log.w(TAG, "Error when calculating MD5 hash"); // return ""; // } // } // } // // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStub.java // public enum Behavior { // DEFAULT, // NO_REPLY, // FAILURE, // TRUNCATED_DATA // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStubWorker.java import edu.berkeley.boinc.Md5; import edu.berkeley.boinc.testutil.BoincClientStub.Behavior; import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc.testutil; public class BoincClientStubWorker { private static final String TAG = "BoincClientStubWorker"; private static final int READ_BUF_SIZE = 8192; private Socket mSocket; private PrintWriter mOutput; private BufferedReader mInput; private StringBuilder mStringBuilder = new StringBuilder(); private boolean mProcessing = false;
private Behavior mBehavior = Behavior.DEFAULT;
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStubWorker.java
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/Md5.java // public class Md5 { // public static final String TAG = "Md5"; // // /** // * Hashes the input string // * // * @param text The text to be hashed // * @return The hash of the input converted to string // */ // public final static String hash(String text) { // try { // MessageDigest md5 = MessageDigest.getInstance("MD5"); // md5.update(text.getBytes("iso-8859-1"), 0, text.length()); // byte[] md5hash = md5.digest(); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i < md5hash.length; ++i) { // sb.append(String.format("%02x", md5hash[i])); // } // return sb.toString(); // } // catch (Exception e) { // Log.w(TAG, "Error when calculating MD5 hash"); // return ""; // } // } // } // // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStub.java // public enum Behavior { // DEFAULT, // NO_REPLY, // FAILURE, // TRUNCATED_DATA // }
import edu.berkeley.boinc.Md5; import edu.berkeley.boinc.testutil.BoincClientStub.Behavior; import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket;
private void handleRequest(String request) { Log.d(TAG, "handleRequest(" + request + ")"); Behavior behavior; synchronized (this) { behavior = mBehavior; } if (behavior == Behavior.NO_REPLY) { Log.d(TAG, "handleRequest(): behavior NO_REPLY, not doing anything"); return; } else if (behavior == Behavior.TRUNCATED_DATA) { mOutput.println("<boinc_gui_rpc_reply>"); mOutput.print("<"); mOutput.flush(); return; } else if (behavior == Behavior.FAILURE) { mOutput.println("<boinc_gui_rpc_reply>"); mOutput.println("<failure/>"); mOutput.print("</boinc_gui_rpc_reply>"); mOutput.print('\003'); mOutput.flush(); return; } String detectedRequest = RpcRequestParser.parse(request); if (detectedRequest.equals("auth1")) { // Authorization part 1 if (!mAuthorized) { final float nonce = System.currentTimeMillis() / 1000;
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/Md5.java // public class Md5 { // public static final String TAG = "Md5"; // // /** // * Hashes the input string // * // * @param text The text to be hashed // * @return The hash of the input converted to string // */ // public final static String hash(String text) { // try { // MessageDigest md5 = MessageDigest.getInstance("MD5"); // md5.update(text.getBytes("iso-8859-1"), 0, text.length()); // byte[] md5hash = md5.digest(); // StringBuilder sb = new StringBuilder(); // for (int i = 0; i < md5hash.length; ++i) { // sb.append(String.format("%02x", md5hash[i])); // } // return sb.toString(); // } // catch (Exception e) { // Log.w(TAG, "Error when calculating MD5 hash"); // return ""; // } // } // } // // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStub.java // public enum Behavior { // DEFAULT, // NO_REPLY, // FAILURE, // TRUNCATED_DATA // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStubWorker.java import edu.berkeley.boinc.Md5; import edu.berkeley.boinc.testutil.BoincClientStub.Behavior; import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; private void handleRequest(String request) { Log.d(TAG, "handleRequest(" + request + ")"); Behavior behavior; synchronized (this) { behavior = mBehavior; } if (behavior == Behavior.NO_REPLY) { Log.d(TAG, "handleRequest(): behavior NO_REPLY, not doing anything"); return; } else if (behavior == Behavior.TRUNCATED_DATA) { mOutput.println("<boinc_gui_rpc_reply>"); mOutput.print("<"); mOutput.flush(); return; } else if (behavior == Behavior.FAILURE) { mOutput.println("<boinc_gui_rpc_reply>"); mOutput.println("<failure/>"); mOutput.print("</boinc_gui_rpc_reply>"); mOutput.print('\003'); mOutput.flush(); return; } String detectedRequest = RpcRequestParser.parse(request); if (detectedRequest.equals("auth1")) { // Authorization part 1 if (!mAuthorized) { final float nonce = System.currentTimeMillis() / 1000;
mNonceHash = Md5.hash(Float.toString(nonce) + mPassword);
palo-m/androboinc
AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/BridgeManager.java
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/NetStats.java // public interface NetStats { // public abstract void connectionOpened(); // public abstract void bytesReceived(int numBytes); // public abstract void bytesTransferred(int numBytes); // public abstract void connectionClosed(); // }
import android.content.Context; import android.os.Handler; import android.util.Log; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import sk.boinc.androboinc.BuildConfig; import sk.boinc.androboinc.clientconnection.ClientReplyReceiver; import sk.boinc.androboinc.clientconnection.ConnectionManager; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback; import sk.boinc.androboinc.clientconnection.ConnectivityListener; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.DisconnectCause; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.ProgressInd; import sk.boinc.androboinc.clientconnection.StatusNotifier; import sk.boinc.androboinc.clientconnection.VersionInfo; import edu.berkeley.boinc.NetStats; import sk.boinc.androboinc.util.ClientId;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package sk.boinc.androboinc.bridge; /** * Manager for client bridge connections. * The service which created this manager should call {@link #cleanup()} method * before the service is terminated to ensure that connection is closed properly. * * @see sk.boinc.androboinc.clientconnection.ConnectionManager */ public class BridgeManager implements ConnectionManager, ClientBridgeCallback, ConnectivityListener { private static final String TAG = "BridgeManager"; private final Context mContext; private final StatusNotifier mNotifier;
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/NetStats.java // public interface NetStats { // public abstract void connectionOpened(); // public abstract void bytesReceived(int numBytes); // public abstract void bytesTransferred(int numBytes); // public abstract void connectionClosed(); // } // Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/BridgeManager.java import android.content.Context; import android.os.Handler; import android.util.Log; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import sk.boinc.androboinc.BuildConfig; import sk.boinc.androboinc.clientconnection.ClientReplyReceiver; import sk.boinc.androboinc.clientconnection.ConnectionManager; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback; import sk.boinc.androboinc.clientconnection.ConnectivityListener; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.DisconnectCause; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.ProgressInd; import sk.boinc.androboinc.clientconnection.StatusNotifier; import sk.boinc.androboinc.clientconnection.VersionInfo; import edu.berkeley.boinc.NetStats; import sk.boinc.androboinc.util.ClientId; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package sk.boinc.androboinc.bridge; /** * Manager for client bridge connections. * The service which created this manager should call {@link #cleanup()} method * before the service is terminated to ensure that connection is closed properly. * * @see sk.boinc.androboinc.clientconnection.ConnectionManager */ public class BridgeManager implements ConnectionManager, ClientBridgeCallback, ConnectivityListener { private static final String TAG = "BridgeManager"; private final Context mContext; private final StatusNotifier mNotifier;
private final NetStats mNetStats;
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/ProjectsParserTest.java
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // }
import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import java.util.Vector; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class ProjectsParserTest { @Test public void parseNormal() {
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/ProjectsParserTest.java import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import java.util.Vector; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class ProjectsParserTest { @Test public void parseNormal() {
final String received = TestSupport.readResource(edu.berkeley.boinc.test.R.raw.get_project_status_reply);
palo-m/androboinc
AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/ClientBridgeWorkerThread.java
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/NetStats.java // public interface NetStats { // public abstract void connectionOpened(); // public abstract void bytesReceived(int numBytes); // public abstract void bytesTransferred(int numBytes); // public abstract void connectionClosed(); // }
import sk.boinc.androboinc.BuildConfig; import sk.boinc.androboinc.clientconnection.ClientReplyReceiver; import sk.boinc.androboinc.clientconnection.HostInfo; import sk.boinc.androboinc.clientconnection.MessageInfo; import sk.boinc.androboinc.clientconnection.ModeInfo; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.DisconnectCause; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.ProgressInd; import sk.boinc.androboinc.clientconnection.ProjectInfo; import sk.boinc.androboinc.clientconnection.TaskInfo; import sk.boinc.androboinc.clientconnection.TransferInfo; import sk.boinc.androboinc.clientconnection.VersionInfo; import edu.berkeley.boinc.NetStats; import sk.boinc.androboinc.util.ClientId; import android.content.Context; import android.os.ConditionVariable; import android.os.Handler; import android.os.Looper; import android.util.Log; import java.util.Vector;
public void run() { mBridgeReply.updatedTasks(callback, tasks); } }); } public void updatedTransfers(final ClientReplyReceiver callback, final Vector <TransferInfo> transfers) { mBridgeReplyHandler.post(new Runnable() { @Override public void run() { mBridgeReply.updatedTransfers(callback, transfers); } }); } public void updatedMessages(final ClientReplyReceiver callback, final Vector <MessageInfo> messages) { mBridgeReplyHandler.post(new Runnable() { @Override public void run() { mBridgeReply.updatedMessages(callback, messages); } }); } } private ReplyHandler mReplyHandler; private ClientBridgeWorkerHandler mHandler; private ConditionVariable mLock; private ClientBridge.BridgeReply mBridgeReply; private Context mContext;
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/NetStats.java // public interface NetStats { // public abstract void connectionOpened(); // public abstract void bytesReceived(int numBytes); // public abstract void bytesTransferred(int numBytes); // public abstract void connectionClosed(); // } // Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/ClientBridgeWorkerThread.java import sk.boinc.androboinc.BuildConfig; import sk.boinc.androboinc.clientconnection.ClientReplyReceiver; import sk.boinc.androboinc.clientconnection.HostInfo; import sk.boinc.androboinc.clientconnection.MessageInfo; import sk.boinc.androboinc.clientconnection.ModeInfo; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.DisconnectCause; import sk.boinc.androboinc.clientconnection.ConnectionManagerCallback.ProgressInd; import sk.boinc.androboinc.clientconnection.ProjectInfo; import sk.boinc.androboinc.clientconnection.TaskInfo; import sk.boinc.androboinc.clientconnection.TransferInfo; import sk.boinc.androboinc.clientconnection.VersionInfo; import edu.berkeley.boinc.NetStats; import sk.boinc.androboinc.util.ClientId; import android.content.Context; import android.os.ConditionVariable; import android.os.Handler; import android.os.Looper; import android.util.Log; import java.util.Vector; public void run() { mBridgeReply.updatedTasks(callback, tasks); } }); } public void updatedTransfers(final ClientReplyReceiver callback, final Vector <TransferInfo> transfers) { mBridgeReplyHandler.post(new Runnable() { @Override public void run() { mBridgeReply.updatedTransfers(callback, transfers); } }); } public void updatedMessages(final ClientReplyReceiver callback, final Vector <MessageInfo> messages) { mBridgeReplyHandler.post(new Runnable() { @Override public void run() { mBridgeReply.updatedMessages(callback, messages); } }); } } private ReplyHandler mReplyHandler; private ClientBridgeWorkerHandler mHandler; private ConditionVariable mLock; private ClientBridge.BridgeReply mBridgeReply; private Context mContext;
private NetStats mNetStats;
palo-m/androboinc
AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/TransferInfoCreator.java
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/Transfer.java // public class Transfer { // public String name; // public String project_url; // public boolean is_upload; // public long nbytes; // public boolean xfer_active; // public int status; // public long next_request_time; // public long time_so_far; // public long bytes_xferred; // public float xfer_speed; // public long project_backoff; // }
import edu.berkeley.boinc.Transfer; import sk.boinc.androboinc.R; import sk.boinc.androboinc.clientconnection.TransferInfo; import android.content.res.Resources;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package sk.boinc.androboinc.bridge; public class TransferInfoCreator { public static final int ERR_GIVEUP_DOWNLOAD = -114; public static final int ERR_GIVEUP_UPLOAD = -115;
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/Transfer.java // public class Transfer { // public String name; // public String project_url; // public boolean is_upload; // public long nbytes; // public boolean xfer_active; // public int status; // public long next_request_time; // public long time_so_far; // public long bytes_xferred; // public float xfer_speed; // public long project_backoff; // } // Path: AndroBOINC/src/main/java/sk/boinc/androboinc/bridge/TransferInfoCreator.java import edu.berkeley.boinc.Transfer; import sk.boinc.androboinc.R; import sk.boinc.androboinc.clientconnection.TransferInfo; import android.content.res.Resources; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package sk.boinc.androboinc.bridge; public class TransferInfoCreator { public static final int ERR_GIVEUP_DOWNLOAD = -114; public static final int ERR_GIVEUP_UPLOAD = -115;
public static TransferInfo create(final Transfer transfer, final String projectName, final Formatter formatter) {
palo-m/androboinc
BoincRpc/src/androidTest/java/edu/berkeley/boinc/HostInfoParserTest.java
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // }
import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*;
/* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class HostInfoParserTest { @Test public void parseNormalNoGpu() {
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/TestSupport.java // public class TestSupport { // // public static String readResource(int resourceId, int maxSize) { // InputStream stream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(resourceId); // assertNotNull(stream); // StringBuilder sb = new StringBuilder(); // String strLine; // try { // BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); // while ((strLine = reader.readLine()) != null) { // sb.append(strLine); // sb.append("\n"); // } // } // catch (IOException e) { // fail("IOException"); // } // // Truncate that last newline // if (sb.length() > 0) { // sb.setLength(sb.length() - 1); // } // if (maxSize > 0) { // if (sb.length() > maxSize) { // sb.setLength(maxSize); // } // } // return sb.toString(); // } // // public static String readResource(int resourceId) { // return readResource(resourceId, 0); // } // } // Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/HostInfoParserTest.java import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import edu.berkeley.boinc.testutil.TestSupport; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; /* * AndroBOINC - BOINC Manager for Android * Copyright (C) 2010 - 2016, Pavol Michalec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package edu.berkeley.boinc; @RunWith(AndroidJUnit4.class) @SmallTest public class HostInfoParserTest { @Test public void parseNormalNoGpu() {
final String received = TestSupport.readResource(edu.berkeley.boinc.test.R.raw.get_host_info_reply_nogpu);
jitsi/otr4j
src/test/java/net/java/otr4j/session/DummyClient.java
// Path: src/main/java/net/java/otr4j/OtrEngineHost.java // public interface OtrEngineHost { // void injectMessage(SessionID sessionID, String msg) // throws OtrException; // // void unreadableMessageReceived(SessionID sessionID) // throws OtrException; // // void unencryptedMessageReceived(SessionID sessionID, // String msg) throws OtrException; // // void showError(SessionID sessionID, String error) // throws OtrException; // // void smpError(SessionID sessionID, int tlvType, // boolean cheated) throws OtrException; // // void smpAborted(SessionID sessionID) throws OtrException; // // void finishedSessionMessage(SessionID sessionID, // String msgText) throws OtrException; // // void requireEncryptedMessage(SessionID sessionID, // String msgText) throws OtrException; // // OtrPolicy getSessionPolicy(SessionID sessionID); // // /** // * Get instructions for the necessary fragmentation operations. // * // * If no fragmentation is necessary, return {@code null} to set the default // * fragmentation instructions which are to use an unlimited number of // * messages of unlimited size each. Hence fragmentation is not necessary or // * applied. // * // * @param sessionID // * the session ID of the session // * @return return fragmentation instructions or null for defaults (i.e. no // * fragmentation) // */ // FragmenterInstructions getFragmenterInstructions(SessionID sessionID); // // KeyPair getLocalKeyPair(SessionID sessionID) // throws OtrException; // // byte[] getLocalFingerprintRaw(SessionID sessionID); // // void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question); // // void verify(SessionID sessionID, String fingerprint, boolean approved); // // void unverify(SessionID sessionID, String fingerprint); // // String getReplyForUnreadableMessage(SessionID sessionID); // // String getFallbackMessage(SessionID sessionID); // // void messageFromAnotherInstanceReceived(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // }
import java.security.KeyPair; import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.logging.Logger; import net.java.otr4j.OtrEngineHost; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoException;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public class DummyClient { private static Logger logger = Logger.getLogger(SessionImplTest.class .getName()); private final String account; private Session session;
// Path: src/main/java/net/java/otr4j/OtrEngineHost.java // public interface OtrEngineHost { // void injectMessage(SessionID sessionID, String msg) // throws OtrException; // // void unreadableMessageReceived(SessionID sessionID) // throws OtrException; // // void unencryptedMessageReceived(SessionID sessionID, // String msg) throws OtrException; // // void showError(SessionID sessionID, String error) // throws OtrException; // // void smpError(SessionID sessionID, int tlvType, // boolean cheated) throws OtrException; // // void smpAborted(SessionID sessionID) throws OtrException; // // void finishedSessionMessage(SessionID sessionID, // String msgText) throws OtrException; // // void requireEncryptedMessage(SessionID sessionID, // String msgText) throws OtrException; // // OtrPolicy getSessionPolicy(SessionID sessionID); // // /** // * Get instructions for the necessary fragmentation operations. // * // * If no fragmentation is necessary, return {@code null} to set the default // * fragmentation instructions which are to use an unlimited number of // * messages of unlimited size each. Hence fragmentation is not necessary or // * applied. // * // * @param sessionID // * the session ID of the session // * @return return fragmentation instructions or null for defaults (i.e. no // * fragmentation) // */ // FragmenterInstructions getFragmenterInstructions(SessionID sessionID); // // KeyPair getLocalKeyPair(SessionID sessionID) // throws OtrException; // // byte[] getLocalFingerprintRaw(SessionID sessionID); // // void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question); // // void verify(SessionID sessionID, String fingerprint, boolean approved); // // void unverify(SessionID sessionID, String fingerprint); // // String getReplyForUnreadableMessage(SessionID sessionID); // // String getFallbackMessage(SessionID sessionID); // // void messageFromAnotherInstanceReceived(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // Path: src/test/java/net/java/otr4j/session/DummyClient.java import java.security.KeyPair; import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.logging.Logger; import net.java.otr4j.OtrEngineHost; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoException; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public class DummyClient { private static Logger logger = Logger.getLogger(SessionImplTest.class .getName()); private final String account; private Session session;
private OtrPolicy policy;
jitsi/otr4j
src/test/java/net/java/otr4j/session/DummyClient.java
// Path: src/main/java/net/java/otr4j/OtrEngineHost.java // public interface OtrEngineHost { // void injectMessage(SessionID sessionID, String msg) // throws OtrException; // // void unreadableMessageReceived(SessionID sessionID) // throws OtrException; // // void unencryptedMessageReceived(SessionID sessionID, // String msg) throws OtrException; // // void showError(SessionID sessionID, String error) // throws OtrException; // // void smpError(SessionID sessionID, int tlvType, // boolean cheated) throws OtrException; // // void smpAborted(SessionID sessionID) throws OtrException; // // void finishedSessionMessage(SessionID sessionID, // String msgText) throws OtrException; // // void requireEncryptedMessage(SessionID sessionID, // String msgText) throws OtrException; // // OtrPolicy getSessionPolicy(SessionID sessionID); // // /** // * Get instructions for the necessary fragmentation operations. // * // * If no fragmentation is necessary, return {@code null} to set the default // * fragmentation instructions which are to use an unlimited number of // * messages of unlimited size each. Hence fragmentation is not necessary or // * applied. // * // * @param sessionID // * the session ID of the session // * @return return fragmentation instructions or null for defaults (i.e. no // * fragmentation) // */ // FragmenterInstructions getFragmenterInstructions(SessionID sessionID); // // KeyPair getLocalKeyPair(SessionID sessionID) // throws OtrException; // // byte[] getLocalFingerprintRaw(SessionID sessionID); // // void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question); // // void verify(SessionID sessionID, String fingerprint, boolean approved); // // void unverify(SessionID sessionID, String fingerprint); // // String getReplyForUnreadableMessage(SessionID sessionID); // // String getFallbackMessage(SessionID sessionID); // // void messageFromAnotherInstanceReceived(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // }
import java.security.KeyPair; import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.logging.Logger; import net.java.otr4j.OtrEngineHost; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoException;
stop(); } } else { try { process(m); } catch (OtrException e) { e.printStackTrace(); stopped = true; } } } } } public void enqueue(String sender, String s) { synchronized (messageQueue) { messageQueue.add(new Message(sender, s)); messageQueue.notify(); } } public void stop() { stopped = true; synchronized (messageQueue) { messageQueue.notify(); } } }
// Path: src/main/java/net/java/otr4j/OtrEngineHost.java // public interface OtrEngineHost { // void injectMessage(SessionID sessionID, String msg) // throws OtrException; // // void unreadableMessageReceived(SessionID sessionID) // throws OtrException; // // void unencryptedMessageReceived(SessionID sessionID, // String msg) throws OtrException; // // void showError(SessionID sessionID, String error) // throws OtrException; // // void smpError(SessionID sessionID, int tlvType, // boolean cheated) throws OtrException; // // void smpAborted(SessionID sessionID) throws OtrException; // // void finishedSessionMessage(SessionID sessionID, // String msgText) throws OtrException; // // void requireEncryptedMessage(SessionID sessionID, // String msgText) throws OtrException; // // OtrPolicy getSessionPolicy(SessionID sessionID); // // /** // * Get instructions for the necessary fragmentation operations. // * // * If no fragmentation is necessary, return {@code null} to set the default // * fragmentation instructions which are to use an unlimited number of // * messages of unlimited size each. Hence fragmentation is not necessary or // * applied. // * // * @param sessionID // * the session ID of the session // * @return return fragmentation instructions or null for defaults (i.e. no // * fragmentation) // */ // FragmenterInstructions getFragmenterInstructions(SessionID sessionID); // // KeyPair getLocalKeyPair(SessionID sessionID) // throws OtrException; // // byte[] getLocalFingerprintRaw(SessionID sessionID); // // void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question); // // void verify(SessionID sessionID, String fingerprint, boolean approved); // // void unverify(SessionID sessionID, String fingerprint); // // String getReplyForUnreadableMessage(SessionID sessionID); // // String getFallbackMessage(SessionID sessionID); // // void messageFromAnotherInstanceReceived(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // Path: src/test/java/net/java/otr4j/session/DummyClient.java import java.security.KeyPair; import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.logging.Logger; import net.java.otr4j.OtrEngineHost; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoException; stop(); } } else { try { process(m); } catch (OtrException e) { e.printStackTrace(); stopped = true; } } } } } public void enqueue(String sender, String s) { synchronized (messageQueue) { messageQueue.add(new Message(sender, s)); messageQueue.notify(); } } public void stop() { stopped = true; synchronized (messageQueue) { messageQueue.notify(); } } }
class DummyOtrEngineHostImpl implements OtrEngineHost {
jitsi/otr4j
src/main/java/net/java/otr4j/session/SessionKeys.java
// Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // }
import java.math.BigInteger; import java.security.KeyPair; import javax.crypto.interfaces.DHPublicKey; import net.java.otr4j.OtrException;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface SessionKeys { int PREVIOUS = 0; int CURRENT = 1; /** @deprecated use {@link #PREVIOUS} instead */ int Previous = PREVIOUS; /** @deprecated use {@link #CURRENT} instead */ int Current = CURRENT; byte HIGH_SEND_BYTE = (byte) 0x01; byte HIGH_RECEIVE_BYTE = (byte) 0x02; byte LOW_SEND_BYTE = (byte) 0x02; byte LOW_RECEIVE_BYTE = (byte) 0x01; void setLocalPair(KeyPair keyPair, int localPairKeyID); void setRemoteDHPublicKey(DHPublicKey pubKey, int remoteKeyID); void incrementSendingCtr(); byte[] getSendingCtr(); byte[] getReceivingCtr(); void setReceivingCtr(byte[] ctr);
// Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // Path: src/main/java/net/java/otr4j/session/SessionKeys.java import java.math.BigInteger; import java.security.KeyPair; import javax.crypto.interfaces.DHPublicKey; import net.java.otr4j.OtrException; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface SessionKeys { int PREVIOUS = 0; int CURRENT = 1; /** @deprecated use {@link #PREVIOUS} instead */ int Previous = PREVIOUS; /** @deprecated use {@link #CURRENT} instead */ int Current = CURRENT; byte HIGH_SEND_BYTE = (byte) 0x01; byte HIGH_RECEIVE_BYTE = (byte) 0x02; byte LOW_SEND_BYTE = (byte) 0x02; byte LOW_RECEIVE_BYTE = (byte) 0x01; void setLocalPair(KeyPair keyPair, int localPairKeyID); void setRemoteDHPublicKey(DHPublicKey pubKey, int remoteKeyID); void incrementSendingCtr(); byte[] getSendingCtr(); byte[] getReceivingCtr(); void setReceivingCtr(byte[] ctr);
byte[] getSendingAESKey() throws OtrException;
jitsi/otr4j
src/test/java/net/java/otr4j/io/IOTest.java
// Path: src/main/java/net/java/otr4j/io/messages/DHKeyMessage.java // public class DHKeyMessage extends AbstractEncodedMessage { // // public DHPublicKey dhPublicKey; // // public DHKeyMessage(int protocolVersion, DHPublicKey dhPublicKey) { // super(MESSAGE_DHKEY, protocolVersion); // this.dhPublicKey = dhPublicKey; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = super.hashCode(); // // TODO: Needs work. // result = prime * result // + ((dhPublicKey == null) ? 0 : dhPublicKey.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (!super.equals(obj)) // return false; // if (getClass() != obj.getClass()) // return false; // DHKeyMessage other = (DHKeyMessage) obj; // if (dhPublicKey == null) { // if (other.dhPublicKey != null) // return false; // } else if (dhPublicKey.getY().compareTo(other.dhPublicKey.getY()) != 0) // return false; // return true; // } // } // // Path: src/main/java/net/java/otr4j/io/messages/RevealSignatureMessage.java // public class RevealSignatureMessage extends SignatureMessage { // // public byte[] revealedKey; // // public RevealSignatureMessage(int protocolVersion, byte[] xEncrypted, // byte[] xEncryptedMAC, byte[] revealedKey) // { // super(MESSAGE_REVEALSIG, protocolVersion, xEncrypted, xEncryptedMAC); // // this.revealedKey = revealedKey; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = super.hashCode(); // result = prime * result + Arrays.hashCode(revealedKey); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (!super.equals(obj)) // return false; // if (getClass() != obj.getClass()) // return false; // RevealSignatureMessage other = (RevealSignatureMessage) obj; // if (!Arrays.equals(revealedKey, other.revealedKey)) // return false; // return true; // } // }
import static org.junit.Assert.assertArrayEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.math.BigInteger; import java.security.KeyPair; import javax.crypto.interfaces.DHPublicKey; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.io.messages.DHKeyMessage; import net.java.otr4j.io.messages.RevealSignatureMessage;
byte[] converted = out.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(converted); OtrInputStream ois = new OtrInputStream(bin); BigInteger result = ois.readBigInt(); assertEquals(0, source.compareTo(result)); } public void testIODHPublicKey() throws Exception { KeyPair pair = new OtrCryptoEngineImpl().generateDHKeyPair(); DHPublicKey source = (DHPublicKey) pair.getPublic(); ByteArrayOutputStream out = new ByteArrayOutputStream(); OtrOutputStream oos = new OtrOutputStream(out); oos.writeDHPublicKey(source); byte[] converted = out.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(converted); OtrInputStream ois = new OtrInputStream(bin); DHPublicKey result = ois.readDHPublicKey(); assertEquals(0, source.getY().compareTo(result.getY())); } public void testIODHKeyMessage() throws Exception { KeyPair pair = new OtrCryptoEngineImpl().generateDHKeyPair();
// Path: src/main/java/net/java/otr4j/io/messages/DHKeyMessage.java // public class DHKeyMessage extends AbstractEncodedMessage { // // public DHPublicKey dhPublicKey; // // public DHKeyMessage(int protocolVersion, DHPublicKey dhPublicKey) { // super(MESSAGE_DHKEY, protocolVersion); // this.dhPublicKey = dhPublicKey; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = super.hashCode(); // // TODO: Needs work. // result = prime * result // + ((dhPublicKey == null) ? 0 : dhPublicKey.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (!super.equals(obj)) // return false; // if (getClass() != obj.getClass()) // return false; // DHKeyMessage other = (DHKeyMessage) obj; // if (dhPublicKey == null) { // if (other.dhPublicKey != null) // return false; // } else if (dhPublicKey.getY().compareTo(other.dhPublicKey.getY()) != 0) // return false; // return true; // } // } // // Path: src/main/java/net/java/otr4j/io/messages/RevealSignatureMessage.java // public class RevealSignatureMessage extends SignatureMessage { // // public byte[] revealedKey; // // public RevealSignatureMessage(int protocolVersion, byte[] xEncrypted, // byte[] xEncryptedMAC, byte[] revealedKey) // { // super(MESSAGE_REVEALSIG, protocolVersion, xEncrypted, xEncryptedMAC); // // this.revealedKey = revealedKey; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = super.hashCode(); // result = prime * result + Arrays.hashCode(revealedKey); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (!super.equals(obj)) // return false; // if (getClass() != obj.getClass()) // return false; // RevealSignatureMessage other = (RevealSignatureMessage) obj; // if (!Arrays.equals(revealedKey, other.revealedKey)) // return false; // return true; // } // } // Path: src/test/java/net/java/otr4j/io/IOTest.java import static org.junit.Assert.assertArrayEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.math.BigInteger; import java.security.KeyPair; import javax.crypto.interfaces.DHPublicKey; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.io.messages.DHKeyMessage; import net.java.otr4j.io.messages.RevealSignatureMessage; byte[] converted = out.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(converted); OtrInputStream ois = new OtrInputStream(bin); BigInteger result = ois.readBigInt(); assertEquals(0, source.compareTo(result)); } public void testIODHPublicKey() throws Exception { KeyPair pair = new OtrCryptoEngineImpl().generateDHKeyPair(); DHPublicKey source = (DHPublicKey) pair.getPublic(); ByteArrayOutputStream out = new ByteArrayOutputStream(); OtrOutputStream oos = new OtrOutputStream(out); oos.writeDHPublicKey(source); byte[] converted = out.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(converted); OtrInputStream ois = new OtrInputStream(bin); DHPublicKey result = ois.readDHPublicKey(); assertEquals(0, source.getY().compareTo(result.getY())); } public void testIODHKeyMessage() throws Exception { KeyPair pair = new OtrCryptoEngineImpl().generateDHKeyPair();
DHKeyMessage source = new DHKeyMessage(0, (DHPublicKey) pair
jitsi/otr4j
src/test/java/net/java/otr4j/io/IOTest.java
// Path: src/main/java/net/java/otr4j/io/messages/DHKeyMessage.java // public class DHKeyMessage extends AbstractEncodedMessage { // // public DHPublicKey dhPublicKey; // // public DHKeyMessage(int protocolVersion, DHPublicKey dhPublicKey) { // super(MESSAGE_DHKEY, protocolVersion); // this.dhPublicKey = dhPublicKey; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = super.hashCode(); // // TODO: Needs work. // result = prime * result // + ((dhPublicKey == null) ? 0 : dhPublicKey.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (!super.equals(obj)) // return false; // if (getClass() != obj.getClass()) // return false; // DHKeyMessage other = (DHKeyMessage) obj; // if (dhPublicKey == null) { // if (other.dhPublicKey != null) // return false; // } else if (dhPublicKey.getY().compareTo(other.dhPublicKey.getY()) != 0) // return false; // return true; // } // } // // Path: src/main/java/net/java/otr4j/io/messages/RevealSignatureMessage.java // public class RevealSignatureMessage extends SignatureMessage { // // public byte[] revealedKey; // // public RevealSignatureMessage(int protocolVersion, byte[] xEncrypted, // byte[] xEncryptedMAC, byte[] revealedKey) // { // super(MESSAGE_REVEALSIG, protocolVersion, xEncrypted, xEncryptedMAC); // // this.revealedKey = revealedKey; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = super.hashCode(); // result = prime * result + Arrays.hashCode(revealedKey); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (!super.equals(obj)) // return false; // if (getClass() != obj.getClass()) // return false; // RevealSignatureMessage other = (RevealSignatureMessage) obj; // if (!Arrays.equals(revealedKey, other.revealedKey)) // return false; // return true; // } // }
import static org.junit.Assert.assertArrayEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.math.BigInteger; import java.security.KeyPair; import javax.crypto.interfaces.DHPublicKey; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.io.messages.DHKeyMessage; import net.java.otr4j.io.messages.RevealSignatureMessage;
ByteArrayInputStream bin = new ByteArrayInputStream(converted); OtrInputStream ois = new OtrInputStream(bin); DHPublicKey result = ois.readDHPublicKey(); assertEquals(0, source.getY().compareTo(result.getY())); } public void testIODHKeyMessage() throws Exception { KeyPair pair = new OtrCryptoEngineImpl().generateDHKeyPair(); DHKeyMessage source = new DHKeyMessage(0, (DHPublicKey) pair .getPublic()); String base64 = SerializationUtils.toString(source); DHKeyMessage result = (DHKeyMessage) SerializationUtils .toMessage(base64); assertEquals(source, result); } public void testIORevealSignature() throws Exception { int protocolVersion = 1; byte[] xEncrypted = new byte[] { 1, 2, 3, 4 }; byte[] xEncryptedMAC = new byte[SerializationConstants.TYPE_LEN_MAC]; for (int i = 0; i < xEncryptedMAC.length; i++) xEncryptedMAC[i] = (byte) i; byte[] revealedKey = new byte[] { 1, 2, 3, 4 };
// Path: src/main/java/net/java/otr4j/io/messages/DHKeyMessage.java // public class DHKeyMessage extends AbstractEncodedMessage { // // public DHPublicKey dhPublicKey; // // public DHKeyMessage(int protocolVersion, DHPublicKey dhPublicKey) { // super(MESSAGE_DHKEY, protocolVersion); // this.dhPublicKey = dhPublicKey; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = super.hashCode(); // // TODO: Needs work. // result = prime * result // + ((dhPublicKey == null) ? 0 : dhPublicKey.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (!super.equals(obj)) // return false; // if (getClass() != obj.getClass()) // return false; // DHKeyMessage other = (DHKeyMessage) obj; // if (dhPublicKey == null) { // if (other.dhPublicKey != null) // return false; // } else if (dhPublicKey.getY().compareTo(other.dhPublicKey.getY()) != 0) // return false; // return true; // } // } // // Path: src/main/java/net/java/otr4j/io/messages/RevealSignatureMessage.java // public class RevealSignatureMessage extends SignatureMessage { // // public byte[] revealedKey; // // public RevealSignatureMessage(int protocolVersion, byte[] xEncrypted, // byte[] xEncryptedMAC, byte[] revealedKey) // { // super(MESSAGE_REVEALSIG, protocolVersion, xEncrypted, xEncryptedMAC); // // this.revealedKey = revealedKey; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = super.hashCode(); // result = prime * result + Arrays.hashCode(revealedKey); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (!super.equals(obj)) // return false; // if (getClass() != obj.getClass()) // return false; // RevealSignatureMessage other = (RevealSignatureMessage) obj; // if (!Arrays.equals(revealedKey, other.revealedKey)) // return false; // return true; // } // } // Path: src/test/java/net/java/otr4j/io/IOTest.java import static org.junit.Assert.assertArrayEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.math.BigInteger; import java.security.KeyPair; import javax.crypto.interfaces.DHPublicKey; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.io.messages.DHKeyMessage; import net.java.otr4j.io.messages.RevealSignatureMessage; ByteArrayInputStream bin = new ByteArrayInputStream(converted); OtrInputStream ois = new OtrInputStream(bin); DHPublicKey result = ois.readDHPublicKey(); assertEquals(0, source.getY().compareTo(result.getY())); } public void testIODHKeyMessage() throws Exception { KeyPair pair = new OtrCryptoEngineImpl().generateDHKeyPair(); DHKeyMessage source = new DHKeyMessage(0, (DHPublicKey) pair .getPublic()); String base64 = SerializationUtils.toString(source); DHKeyMessage result = (DHKeyMessage) SerializationUtils .toMessage(base64); assertEquals(source, result); } public void testIORevealSignature() throws Exception { int protocolVersion = 1; byte[] xEncrypted = new byte[] { 1, 2, 3, 4 }; byte[] xEncryptedMAC = new byte[SerializationConstants.TYPE_LEN_MAC]; for (int i = 0; i < xEncryptedMAC.length; i++) xEncryptedMAC[i] = (byte) i; byte[] revealedKey = new byte[] { 1, 2, 3, 4 };
RevealSignatureMessage source = new RevealSignatureMessage(
jitsi/otr4j
src/main/java/net/java/otr4j/session/OtrFragmenter.java
// Path: src/main/java/net/java/otr4j/OtrEngineHost.java // public interface OtrEngineHost { // void injectMessage(SessionID sessionID, String msg) // throws OtrException; // // void unreadableMessageReceived(SessionID sessionID) // throws OtrException; // // void unencryptedMessageReceived(SessionID sessionID, // String msg) throws OtrException; // // void showError(SessionID sessionID, String error) // throws OtrException; // // void smpError(SessionID sessionID, int tlvType, // boolean cheated) throws OtrException; // // void smpAborted(SessionID sessionID) throws OtrException; // // void finishedSessionMessage(SessionID sessionID, // String msgText) throws OtrException; // // void requireEncryptedMessage(SessionID sessionID, // String msgText) throws OtrException; // // OtrPolicy getSessionPolicy(SessionID sessionID); // // /** // * Get instructions for the necessary fragmentation operations. // * // * If no fragmentation is necessary, return {@code null} to set the default // * fragmentation instructions which are to use an unlimited number of // * messages of unlimited size each. Hence fragmentation is not necessary or // * applied. // * // * @param sessionID // * the session ID of the session // * @return return fragmentation instructions or null for defaults (i.e. no // * fragmentation) // */ // FragmenterInstructions getFragmenterInstructions(SessionID sessionID); // // KeyPair getLocalKeyPair(SessionID sessionID) // throws OtrException; // // byte[] getLocalFingerprintRaw(SessionID sessionID); // // void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question); // // void verify(SessionID sessionID, String fingerprint, boolean approved); // // void unverify(SessionID sessionID, String fingerprint); // // String getReplyForUnreadableMessage(SessionID sessionID); // // String getFallbackMessage(SessionID sessionID); // // void messageFromAnotherInstanceReceived(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // }
import java.io.IOException; import java.util.LinkedList; import net.java.otr4j.OtrEngineHost; import net.java.otr4j.OtrPolicy;
static int computeHeaderV3Size() { // For a OTRv3 header this seems to be a constant number, since the // specs seem to suggest that smaller numbers have leading zeros. return 36; } /** * Compute the overhead size for a v2 header. * * Current implementation returns an upper bound size for the size of the * header. As I understand it, the protocol does not require leading zeros * to fill a 5-space number are so in theory it is possible to gain a few * extra characters per message if an exact calculation of the number of * required chars is used. * * TODO I think this is dependent on the number of chars in a decimal * representation of the current and total number of fragments. * * @return returns size of v2 header */ static int computeHeaderV2Size() { // currently returns an upper bound (for the case of 10000+ fragments) return 18; } /** * Get the OTR policy. * * @return returns the policy */
// Path: src/main/java/net/java/otr4j/OtrEngineHost.java // public interface OtrEngineHost { // void injectMessage(SessionID sessionID, String msg) // throws OtrException; // // void unreadableMessageReceived(SessionID sessionID) // throws OtrException; // // void unencryptedMessageReceived(SessionID sessionID, // String msg) throws OtrException; // // void showError(SessionID sessionID, String error) // throws OtrException; // // void smpError(SessionID sessionID, int tlvType, // boolean cheated) throws OtrException; // // void smpAborted(SessionID sessionID) throws OtrException; // // void finishedSessionMessage(SessionID sessionID, // String msgText) throws OtrException; // // void requireEncryptedMessage(SessionID sessionID, // String msgText) throws OtrException; // // OtrPolicy getSessionPolicy(SessionID sessionID); // // /** // * Get instructions for the necessary fragmentation operations. // * // * If no fragmentation is necessary, return {@code null} to set the default // * fragmentation instructions which are to use an unlimited number of // * messages of unlimited size each. Hence fragmentation is not necessary or // * applied. // * // * @param sessionID // * the session ID of the session // * @return return fragmentation instructions or null for defaults (i.e. no // * fragmentation) // */ // FragmenterInstructions getFragmenterInstructions(SessionID sessionID); // // KeyPair getLocalKeyPair(SessionID sessionID) // throws OtrException; // // byte[] getLocalFingerprintRaw(SessionID sessionID); // // void askForSecret(SessionID sessionID, InstanceTag receiverTag, String question); // // void verify(SessionID sessionID, String fingerprint, boolean approved); // // void unverify(SessionID sessionID, String fingerprint); // // String getReplyForUnreadableMessage(SessionID sessionID); // // String getFallbackMessage(SessionID sessionID); // // void messageFromAnotherInstanceReceived(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // Path: src/main/java/net/java/otr4j/session/OtrFragmenter.java import java.io.IOException; import java.util.LinkedList; import net.java.otr4j.OtrEngineHost; import net.java.otr4j.OtrPolicy; static int computeHeaderV3Size() { // For a OTRv3 header this seems to be a constant number, since the // specs seem to suggest that smaller numbers have leading zeros. return 36; } /** * Compute the overhead size for a v2 header. * * Current implementation returns an upper bound size for the size of the * header. As I understand it, the protocol does not require leading zeros * to fill a 5-space number are so in theory it is possible to gain a few * extra characters per message if an exact calculation of the number of * required chars is used. * * TODO I think this is dependent on the number of chars in a decimal * representation of the current and total number of fragments. * * @return returns size of v2 header */ static int computeHeaderV2Size() { // currently returns an upper bound (for the case of 10000+ fragments) return 18; } /** * Get the OTR policy. * * @return returns the policy */
private OtrPolicy getPolicy() {
jitsi/otr4j
src/main/java/net/java/otr4j/OtrKeyManagerImpl.java
// Path: src/main/java/net/java/otr4j/session/SessionID.java // public final class SessionID { // // private final String accountID; // private final String userID; // private final String protocolName; // // public static final SessionID EMPTY = new SessionID(null, null, null); // /** @deprecated use {@link #EMPTY} instead */ // public static final SessionID Empty = EMPTY; // // public SessionID(String accountID, String userID, String protocolName) { // this.accountID = accountID; // this.userID = userID; // this.protocolName = protocolName; // } // // public String getAccountID() { // return accountID; // } // // public String getUserID() { // return userID; // } // // public String getProtocolName() { // return protocolName; // } // // @Override // public String toString() { // return accountID + '_' + protocolName + '_' + userID; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result // + ((accountID == null) ? 0 : accountID.hashCode()); // result = prime * result // + ((protocolName == null) ? 0 : protocolName.hashCode()); // result = prime * result + ((userID == null) ? 0 : userID.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // SessionID other = (SessionID) obj; // if (accountID == null) { // if (other.accountID != null) // return false; // } else if (!accountID.equals(other.accountID)) // return false; // if (protocolName == null) { // if (other.protocolName != null) // return false; // } else if (!protocolName.equals(other.protocolName)) // return false; // if (userID == null) { // if (other.userID != null) // return false; // } else if (!userID.equals(other.userID)) // return false; // return true; // } // }
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.Properties; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoException; import net.java.otr4j.session.SessionID;
@Override public boolean getPropertyBoolean(String id, boolean defaultValue) { try { return Boolean.parseBoolean(properties.get(id).toString()); } catch (Exception e) { return defaultValue; } } } public OtrKeyManagerImpl(String filepath) throws IOException { this.store = new DefaultPropertiesStore(filepath); } @Override public void addListener(OtrKeyManagerListener l) { synchronized (listeners) { if (!listeners.contains(l)) listeners.add(l); } } @Override public void removeListener(OtrKeyManagerListener l) { synchronized (listeners) { listeners.remove(l); } } @Override
// Path: src/main/java/net/java/otr4j/session/SessionID.java // public final class SessionID { // // private final String accountID; // private final String userID; // private final String protocolName; // // public static final SessionID EMPTY = new SessionID(null, null, null); // /** @deprecated use {@link #EMPTY} instead */ // public static final SessionID Empty = EMPTY; // // public SessionID(String accountID, String userID, String protocolName) { // this.accountID = accountID; // this.userID = userID; // this.protocolName = protocolName; // } // // public String getAccountID() { // return accountID; // } // // public String getUserID() { // return userID; // } // // public String getProtocolName() { // return protocolName; // } // // @Override // public String toString() { // return accountID + '_' + protocolName + '_' + userID; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result // + ((accountID == null) ? 0 : accountID.hashCode()); // result = prime * result // + ((protocolName == null) ? 0 : protocolName.hashCode()); // result = prime * result + ((userID == null) ? 0 : userID.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // SessionID other = (SessionID) obj; // if (accountID == null) { // if (other.accountID != null) // return false; // } else if (!accountID.equals(other.accountID)) // return false; // if (protocolName == null) { // if (other.protocolName != null) // return false; // } else if (!protocolName.equals(other.protocolName)) // return false; // if (userID == null) { // if (other.userID != null) // return false; // } else if (!userID.equals(other.userID)) // return false; // return true; // } // } // Path: src/main/java/net/java/otr4j/OtrKeyManagerImpl.java import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.Properties; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoException; import net.java.otr4j.session.SessionID; @Override public boolean getPropertyBoolean(String id, boolean defaultValue) { try { return Boolean.parseBoolean(properties.get(id).toString()); } catch (Exception e) { return defaultValue; } } } public OtrKeyManagerImpl(String filepath) throws IOException { this.store = new DefaultPropertiesStore(filepath); } @Override public void addListener(OtrKeyManagerListener l) { synchronized (listeners) { if (!listeners.contains(l)) listeners.add(l); } } @Override public void removeListener(OtrKeyManagerListener l) { synchronized (listeners) { listeners.remove(l); } } @Override
public void generateLocalKeyPair(SessionID sessionID) {
jitsi/otr4j
src/main/java/net/java/otr4j/OtrSessionManagerImpl.java
// Path: src/main/java/net/java/otr4j/session/Session.java // public interface Session { // // interface OTRv { // int ONE = 1; // // int TWO = 2; // // int THREE = 3; // } // // SessionStatus getSessionStatus(); // // SessionID getSessionID(); // // void injectMessage(AbstractMessage m) throws OtrException; // // KeyPair getLocalKeyPair() throws OtrException; // // OtrPolicy getSessionPolicy(); // // String transformReceiving(String content) // throws OtrException; // // String[] transformSending(String content, List<TLV> tlvs) // throws OtrException; // // String[] transformSending(String content) // throws OtrException; // // void startSession() throws OtrException; // // void endSession() throws OtrException; // // void refreshSession() throws OtrException; // // PublicKey getRemotePublicKey(); // // void addOtrEngineListener(OtrEngineListener l); // // void removeOtrEngineListener(OtrEngineListener l); // // void initSmp(String question, String secret) throws OtrException; // // void respondSmp(String question, String secret) throws OtrException; // // void abortSmp() throws OtrException; // // boolean isSmpInProgress(); // // BigInteger getS(); // // // OTRv3 methods // List<Session> getInstances(); // // Session getOutgoingInstance(); // // boolean setOutgoingInstance(InstanceTag tag); // // InstanceTag getSenderInstanceTag(); // // InstanceTag getReceiverInstanceTag(); // // void setReceiverInstanceTag(InstanceTag tag); // // void setProtocolVersion(int protocolVersion); // // int getProtocolVersion(); // // void respondSmp(InstanceTag receiverTag, String question, String secret) // throws OtrException; // // SessionStatus getSessionStatus(InstanceTag tag); // // PublicKey getRemotePublicKey(InstanceTag tag); // } // // Path: src/main/java/net/java/otr4j/session/SessionID.java // public final class SessionID { // // private final String accountID; // private final String userID; // private final String protocolName; // // public static final SessionID EMPTY = new SessionID(null, null, null); // /** @deprecated use {@link #EMPTY} instead */ // public static final SessionID Empty = EMPTY; // // public SessionID(String accountID, String userID, String protocolName) { // this.accountID = accountID; // this.userID = userID; // this.protocolName = protocolName; // } // // public String getAccountID() { // return accountID; // } // // public String getUserID() { // return userID; // } // // public String getProtocolName() { // return protocolName; // } // // @Override // public String toString() { // return accountID + '_' + protocolName + '_' + userID; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result // + ((accountID == null) ? 0 : accountID.hashCode()); // result = prime * result // + ((protocolName == null) ? 0 : protocolName.hashCode()); // result = prime * result + ((userID == null) ? 0 : userID.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // SessionID other = (SessionID) obj; // if (accountID == null) { // if (other.accountID != null) // return false; // } else if (!accountID.equals(other.accountID)) // return false; // if (protocolName == null) { // if (other.protocolName != null) // return false; // } else if (!protocolName.equals(other.protocolName)) // return false; // if (userID == null) { // if (other.userID != null) // return false; // } else if (!userID.equals(other.userID)) // return false; // return true; // } // }
import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Map; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionID; import net.java.otr4j.session.SessionImpl;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j; /** * * @author George Politis */ public class OtrSessionManagerImpl implements OtrSessionManager { private OtrEngineHost host;
// Path: src/main/java/net/java/otr4j/session/Session.java // public interface Session { // // interface OTRv { // int ONE = 1; // // int TWO = 2; // // int THREE = 3; // } // // SessionStatus getSessionStatus(); // // SessionID getSessionID(); // // void injectMessage(AbstractMessage m) throws OtrException; // // KeyPair getLocalKeyPair() throws OtrException; // // OtrPolicy getSessionPolicy(); // // String transformReceiving(String content) // throws OtrException; // // String[] transformSending(String content, List<TLV> tlvs) // throws OtrException; // // String[] transformSending(String content) // throws OtrException; // // void startSession() throws OtrException; // // void endSession() throws OtrException; // // void refreshSession() throws OtrException; // // PublicKey getRemotePublicKey(); // // void addOtrEngineListener(OtrEngineListener l); // // void removeOtrEngineListener(OtrEngineListener l); // // void initSmp(String question, String secret) throws OtrException; // // void respondSmp(String question, String secret) throws OtrException; // // void abortSmp() throws OtrException; // // boolean isSmpInProgress(); // // BigInteger getS(); // // // OTRv3 methods // List<Session> getInstances(); // // Session getOutgoingInstance(); // // boolean setOutgoingInstance(InstanceTag tag); // // InstanceTag getSenderInstanceTag(); // // InstanceTag getReceiverInstanceTag(); // // void setReceiverInstanceTag(InstanceTag tag); // // void setProtocolVersion(int protocolVersion); // // int getProtocolVersion(); // // void respondSmp(InstanceTag receiverTag, String question, String secret) // throws OtrException; // // SessionStatus getSessionStatus(InstanceTag tag); // // PublicKey getRemotePublicKey(InstanceTag tag); // } // // Path: src/main/java/net/java/otr4j/session/SessionID.java // public final class SessionID { // // private final String accountID; // private final String userID; // private final String protocolName; // // public static final SessionID EMPTY = new SessionID(null, null, null); // /** @deprecated use {@link #EMPTY} instead */ // public static final SessionID Empty = EMPTY; // // public SessionID(String accountID, String userID, String protocolName) { // this.accountID = accountID; // this.userID = userID; // this.protocolName = protocolName; // } // // public String getAccountID() { // return accountID; // } // // public String getUserID() { // return userID; // } // // public String getProtocolName() { // return protocolName; // } // // @Override // public String toString() { // return accountID + '_' + protocolName + '_' + userID; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result // + ((accountID == null) ? 0 : accountID.hashCode()); // result = prime * result // + ((protocolName == null) ? 0 : protocolName.hashCode()); // result = prime * result + ((userID == null) ? 0 : userID.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // SessionID other = (SessionID) obj; // if (accountID == null) { // if (other.accountID != null) // return false; // } else if (!accountID.equals(other.accountID)) // return false; // if (protocolName == null) { // if (other.protocolName != null) // return false; // } else if (!protocolName.equals(other.protocolName)) // return false; // if (userID == null) { // if (other.userID != null) // return false; // } else if (!userID.equals(other.userID)) // return false; // return true; // } // } // Path: src/main/java/net/java/otr4j/OtrSessionManagerImpl.java import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Map; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionID; import net.java.otr4j.session.SessionImpl; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j; /** * * @author George Politis */ public class OtrSessionManagerImpl implements OtrSessionManager { private OtrEngineHost host;
private Map<SessionID, Session> sessions;
jitsi/otr4j
src/main/java/net/java/otr4j/OtrSessionManagerImpl.java
// Path: src/main/java/net/java/otr4j/session/Session.java // public interface Session { // // interface OTRv { // int ONE = 1; // // int TWO = 2; // // int THREE = 3; // } // // SessionStatus getSessionStatus(); // // SessionID getSessionID(); // // void injectMessage(AbstractMessage m) throws OtrException; // // KeyPair getLocalKeyPair() throws OtrException; // // OtrPolicy getSessionPolicy(); // // String transformReceiving(String content) // throws OtrException; // // String[] transformSending(String content, List<TLV> tlvs) // throws OtrException; // // String[] transformSending(String content) // throws OtrException; // // void startSession() throws OtrException; // // void endSession() throws OtrException; // // void refreshSession() throws OtrException; // // PublicKey getRemotePublicKey(); // // void addOtrEngineListener(OtrEngineListener l); // // void removeOtrEngineListener(OtrEngineListener l); // // void initSmp(String question, String secret) throws OtrException; // // void respondSmp(String question, String secret) throws OtrException; // // void abortSmp() throws OtrException; // // boolean isSmpInProgress(); // // BigInteger getS(); // // // OTRv3 methods // List<Session> getInstances(); // // Session getOutgoingInstance(); // // boolean setOutgoingInstance(InstanceTag tag); // // InstanceTag getSenderInstanceTag(); // // InstanceTag getReceiverInstanceTag(); // // void setReceiverInstanceTag(InstanceTag tag); // // void setProtocolVersion(int protocolVersion); // // int getProtocolVersion(); // // void respondSmp(InstanceTag receiverTag, String question, String secret) // throws OtrException; // // SessionStatus getSessionStatus(InstanceTag tag); // // PublicKey getRemotePublicKey(InstanceTag tag); // } // // Path: src/main/java/net/java/otr4j/session/SessionID.java // public final class SessionID { // // private final String accountID; // private final String userID; // private final String protocolName; // // public static final SessionID EMPTY = new SessionID(null, null, null); // /** @deprecated use {@link #EMPTY} instead */ // public static final SessionID Empty = EMPTY; // // public SessionID(String accountID, String userID, String protocolName) { // this.accountID = accountID; // this.userID = userID; // this.protocolName = protocolName; // } // // public String getAccountID() { // return accountID; // } // // public String getUserID() { // return userID; // } // // public String getProtocolName() { // return protocolName; // } // // @Override // public String toString() { // return accountID + '_' + protocolName + '_' + userID; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result // + ((accountID == null) ? 0 : accountID.hashCode()); // result = prime * result // + ((protocolName == null) ? 0 : protocolName.hashCode()); // result = prime * result + ((userID == null) ? 0 : userID.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // SessionID other = (SessionID) obj; // if (accountID == null) { // if (other.accountID != null) // return false; // } else if (!accountID.equals(other.accountID)) // return false; // if (protocolName == null) { // if (other.protocolName != null) // return false; // } else if (!protocolName.equals(other.protocolName)) // return false; // if (userID == null) { // if (other.userID != null) // return false; // } else if (!userID.equals(other.userID)) // return false; // return true; // } // }
import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Map; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionID; import net.java.otr4j.session.SessionImpl;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j; /** * * @author George Politis */ public class OtrSessionManagerImpl implements OtrSessionManager { private OtrEngineHost host;
// Path: src/main/java/net/java/otr4j/session/Session.java // public interface Session { // // interface OTRv { // int ONE = 1; // // int TWO = 2; // // int THREE = 3; // } // // SessionStatus getSessionStatus(); // // SessionID getSessionID(); // // void injectMessage(AbstractMessage m) throws OtrException; // // KeyPair getLocalKeyPair() throws OtrException; // // OtrPolicy getSessionPolicy(); // // String transformReceiving(String content) // throws OtrException; // // String[] transformSending(String content, List<TLV> tlvs) // throws OtrException; // // String[] transformSending(String content) // throws OtrException; // // void startSession() throws OtrException; // // void endSession() throws OtrException; // // void refreshSession() throws OtrException; // // PublicKey getRemotePublicKey(); // // void addOtrEngineListener(OtrEngineListener l); // // void removeOtrEngineListener(OtrEngineListener l); // // void initSmp(String question, String secret) throws OtrException; // // void respondSmp(String question, String secret) throws OtrException; // // void abortSmp() throws OtrException; // // boolean isSmpInProgress(); // // BigInteger getS(); // // // OTRv3 methods // List<Session> getInstances(); // // Session getOutgoingInstance(); // // boolean setOutgoingInstance(InstanceTag tag); // // InstanceTag getSenderInstanceTag(); // // InstanceTag getReceiverInstanceTag(); // // void setReceiverInstanceTag(InstanceTag tag); // // void setProtocolVersion(int protocolVersion); // // int getProtocolVersion(); // // void respondSmp(InstanceTag receiverTag, String question, String secret) // throws OtrException; // // SessionStatus getSessionStatus(InstanceTag tag); // // PublicKey getRemotePublicKey(InstanceTag tag); // } // // Path: src/main/java/net/java/otr4j/session/SessionID.java // public final class SessionID { // // private final String accountID; // private final String userID; // private final String protocolName; // // public static final SessionID EMPTY = new SessionID(null, null, null); // /** @deprecated use {@link #EMPTY} instead */ // public static final SessionID Empty = EMPTY; // // public SessionID(String accountID, String userID, String protocolName) { // this.accountID = accountID; // this.userID = userID; // this.protocolName = protocolName; // } // // public String getAccountID() { // return accountID; // } // // public String getUserID() { // return userID; // } // // public String getProtocolName() { // return protocolName; // } // // @Override // public String toString() { // return accountID + '_' + protocolName + '_' + userID; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result // + ((accountID == null) ? 0 : accountID.hashCode()); // result = prime * result // + ((protocolName == null) ? 0 : protocolName.hashCode()); // result = prime * result + ((userID == null) ? 0 : userID.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // SessionID other = (SessionID) obj; // if (accountID == null) { // if (other.accountID != null) // return false; // } else if (!accountID.equals(other.accountID)) // return false; // if (protocolName == null) { // if (other.protocolName != null) // return false; // } else if (!protocolName.equals(other.protocolName)) // return false; // if (userID == null) { // if (other.userID != null) // return false; // } else if (!userID.equals(other.userID)) // return false; // return true; // } // } // Path: src/main/java/net/java/otr4j/OtrSessionManagerImpl.java import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Map; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionID; import net.java.otr4j.session.SessionImpl; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j; /** * * @author George Politis */ public class OtrSessionManagerImpl implements OtrSessionManager { private OtrEngineHost host;
private Map<SessionID, Session> sessions;
jitsi/otr4j
src/main/java/net/java/otr4j/session/Session.java
// Path: src/main/java/net/java/otr4j/OtrEngineListener.java // public interface OtrEngineListener { // void sessionStatusChanged(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // // void outgoingSessionChanged(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // // Path: src/main/java/net/java/otr4j/io/messages/AbstractMessage.java // public abstract class AbstractMessage { // // // Unencoded // public static final int MESSAGE_ERROR = 0xff; // public static final int MESSAGE_QUERY = 0x100; // public static final int MESSAGE_PLAINTEXT = 0x102; // // public int messageType; // // public AbstractMessage(int messageType) { // this.messageType = messageType; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + messageType; // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // AbstractMessage other = (AbstractMessage) obj; // if (messageType != other.messageType) // return false; // return true; // } // }
import java.math.BigInteger; import java.security.KeyPair; import java.security.PublicKey; import java.util.List; import net.java.otr4j.OtrEngineListener; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.io.messages.AbstractMessage;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface Session { interface OTRv { int ONE = 1; int TWO = 2; int THREE = 3; } SessionStatus getSessionStatus(); SessionID getSessionID();
// Path: src/main/java/net/java/otr4j/OtrEngineListener.java // public interface OtrEngineListener { // void sessionStatusChanged(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // // void outgoingSessionChanged(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // // Path: src/main/java/net/java/otr4j/io/messages/AbstractMessage.java // public abstract class AbstractMessage { // // // Unencoded // public static final int MESSAGE_ERROR = 0xff; // public static final int MESSAGE_QUERY = 0x100; // public static final int MESSAGE_PLAINTEXT = 0x102; // // public int messageType; // // public AbstractMessage(int messageType) { // this.messageType = messageType; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + messageType; // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // AbstractMessage other = (AbstractMessage) obj; // if (messageType != other.messageType) // return false; // return true; // } // } // Path: src/main/java/net/java/otr4j/session/Session.java import java.math.BigInteger; import java.security.KeyPair; import java.security.PublicKey; import java.util.List; import net.java.otr4j.OtrEngineListener; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.io.messages.AbstractMessage; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface Session { interface OTRv { int ONE = 1; int TWO = 2; int THREE = 3; } SessionStatus getSessionStatus(); SessionID getSessionID();
void injectMessage(AbstractMessage m) throws OtrException;
jitsi/otr4j
src/main/java/net/java/otr4j/session/Session.java
// Path: src/main/java/net/java/otr4j/OtrEngineListener.java // public interface OtrEngineListener { // void sessionStatusChanged(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // // void outgoingSessionChanged(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // // Path: src/main/java/net/java/otr4j/io/messages/AbstractMessage.java // public abstract class AbstractMessage { // // // Unencoded // public static final int MESSAGE_ERROR = 0xff; // public static final int MESSAGE_QUERY = 0x100; // public static final int MESSAGE_PLAINTEXT = 0x102; // // public int messageType; // // public AbstractMessage(int messageType) { // this.messageType = messageType; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + messageType; // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // AbstractMessage other = (AbstractMessage) obj; // if (messageType != other.messageType) // return false; // return true; // } // }
import java.math.BigInteger; import java.security.KeyPair; import java.security.PublicKey; import java.util.List; import net.java.otr4j.OtrEngineListener; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.io.messages.AbstractMessage;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface Session { interface OTRv { int ONE = 1; int TWO = 2; int THREE = 3; } SessionStatus getSessionStatus(); SessionID getSessionID();
// Path: src/main/java/net/java/otr4j/OtrEngineListener.java // public interface OtrEngineListener { // void sessionStatusChanged(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // // void outgoingSessionChanged(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // // Path: src/main/java/net/java/otr4j/io/messages/AbstractMessage.java // public abstract class AbstractMessage { // // // Unencoded // public static final int MESSAGE_ERROR = 0xff; // public static final int MESSAGE_QUERY = 0x100; // public static final int MESSAGE_PLAINTEXT = 0x102; // // public int messageType; // // public AbstractMessage(int messageType) { // this.messageType = messageType; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + messageType; // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // AbstractMessage other = (AbstractMessage) obj; // if (messageType != other.messageType) // return false; // return true; // } // } // Path: src/main/java/net/java/otr4j/session/Session.java import java.math.BigInteger; import java.security.KeyPair; import java.security.PublicKey; import java.util.List; import net.java.otr4j.OtrEngineListener; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.io.messages.AbstractMessage; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface Session { interface OTRv { int ONE = 1; int TWO = 2; int THREE = 3; } SessionStatus getSessionStatus(); SessionID getSessionID();
void injectMessage(AbstractMessage m) throws OtrException;
jitsi/otr4j
src/main/java/net/java/otr4j/session/Session.java
// Path: src/main/java/net/java/otr4j/OtrEngineListener.java // public interface OtrEngineListener { // void sessionStatusChanged(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // // void outgoingSessionChanged(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // // Path: src/main/java/net/java/otr4j/io/messages/AbstractMessage.java // public abstract class AbstractMessage { // // // Unencoded // public static final int MESSAGE_ERROR = 0xff; // public static final int MESSAGE_QUERY = 0x100; // public static final int MESSAGE_PLAINTEXT = 0x102; // // public int messageType; // // public AbstractMessage(int messageType) { // this.messageType = messageType; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + messageType; // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // AbstractMessage other = (AbstractMessage) obj; // if (messageType != other.messageType) // return false; // return true; // } // }
import java.math.BigInteger; import java.security.KeyPair; import java.security.PublicKey; import java.util.List; import net.java.otr4j.OtrEngineListener; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.io.messages.AbstractMessage;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface Session { interface OTRv { int ONE = 1; int TWO = 2; int THREE = 3; } SessionStatus getSessionStatus(); SessionID getSessionID(); void injectMessage(AbstractMessage m) throws OtrException; KeyPair getLocalKeyPair() throws OtrException;
// Path: src/main/java/net/java/otr4j/OtrEngineListener.java // public interface OtrEngineListener { // void sessionStatusChanged(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // // void outgoingSessionChanged(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // // Path: src/main/java/net/java/otr4j/io/messages/AbstractMessage.java // public abstract class AbstractMessage { // // // Unencoded // public static final int MESSAGE_ERROR = 0xff; // public static final int MESSAGE_QUERY = 0x100; // public static final int MESSAGE_PLAINTEXT = 0x102; // // public int messageType; // // public AbstractMessage(int messageType) { // this.messageType = messageType; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + messageType; // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // AbstractMessage other = (AbstractMessage) obj; // if (messageType != other.messageType) // return false; // return true; // } // } // Path: src/main/java/net/java/otr4j/session/Session.java import java.math.BigInteger; import java.security.KeyPair; import java.security.PublicKey; import java.util.List; import net.java.otr4j.OtrEngineListener; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.io.messages.AbstractMessage; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface Session { interface OTRv { int ONE = 1; int TWO = 2; int THREE = 3; } SessionStatus getSessionStatus(); SessionID getSessionID(); void injectMessage(AbstractMessage m) throws OtrException; KeyPair getLocalKeyPair() throws OtrException;
OtrPolicy getSessionPolicy();
jitsi/otr4j
src/main/java/net/java/otr4j/session/Session.java
// Path: src/main/java/net/java/otr4j/OtrEngineListener.java // public interface OtrEngineListener { // void sessionStatusChanged(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // // void outgoingSessionChanged(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // // Path: src/main/java/net/java/otr4j/io/messages/AbstractMessage.java // public abstract class AbstractMessage { // // // Unencoded // public static final int MESSAGE_ERROR = 0xff; // public static final int MESSAGE_QUERY = 0x100; // public static final int MESSAGE_PLAINTEXT = 0x102; // // public int messageType; // // public AbstractMessage(int messageType) { // this.messageType = messageType; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + messageType; // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // AbstractMessage other = (AbstractMessage) obj; // if (messageType != other.messageType) // return false; // return true; // } // }
import java.math.BigInteger; import java.security.KeyPair; import java.security.PublicKey; import java.util.List; import net.java.otr4j.OtrEngineListener; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.io.messages.AbstractMessage;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface Session { interface OTRv { int ONE = 1; int TWO = 2; int THREE = 3; } SessionStatus getSessionStatus(); SessionID getSessionID(); void injectMessage(AbstractMessage m) throws OtrException; KeyPair getLocalKeyPair() throws OtrException; OtrPolicy getSessionPolicy(); String transformReceiving(String content) throws OtrException; String[] transformSending(String content, List<TLV> tlvs) throws OtrException; String[] transformSending(String content) throws OtrException; void startSession() throws OtrException; void endSession() throws OtrException; void refreshSession() throws OtrException; PublicKey getRemotePublicKey();
// Path: src/main/java/net/java/otr4j/OtrEngineListener.java // public interface OtrEngineListener { // void sessionStatusChanged(SessionID sessionID); // // void multipleInstancesDetected(SessionID sessionID); // // void outgoingSessionChanged(SessionID sessionID); // } // // Path: src/main/java/net/java/otr4j/OtrException.java // @SuppressWarnings("serial") // public class OtrException extends Exception { // public OtrException(Exception e) { // super(e); // } // } // // Path: src/main/java/net/java/otr4j/OtrPolicy.java // public interface OtrPolicy { // // int ALLOW_V1 = 0x01; // int ALLOW_V2 = 0x02; // int ALLOW_V3 = 0x40; // ALLOW_V3 is set to 0x40 for compatibility with older versions // int REQUIRE_ENCRYPTION = 0x04; // int SEND_WHITESPACE_TAG = 0x8; // int WHITESPACE_START_AKE = 0x10; // int ERROR_START_AKE = 0x20; // int VERSION_MASK = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // // // The four old version 1 policies correspond to the following combinations // // of flags (adding an allowance for version 2 of the protocol): // // int NEVER = 0x00; // int OPPORTUNISTIC = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | SEND_WHITESPACE_TAG | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_MANUAL = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3); // int OTRL_POLICY_ALWAYS = (ALLOW_V1 | ALLOW_V2 | ALLOW_V3 // | REQUIRE_ENCRYPTION | WHITESPACE_START_AKE | ERROR_START_AKE); // int OTRL_POLICY_DEFAULT = OPPORTUNISTIC; // // boolean getAllowV1(); // // boolean getAllowV2(); // // boolean getAllowV3(); // // boolean getRequireEncryption(); // // boolean getSendWhitespaceTag(); // // boolean getWhitespaceStartAKE(); // // boolean getErrorStartAKE(); // // int getPolicy(); // // void setAllowV1(boolean value); // // void setAllowV2(boolean value); // // void setAllowV3(boolean value); // // void setRequireEncryption(boolean value); // // void setSendWhitespaceTag(boolean value); // // void setWhitespaceStartAKE(boolean value); // // void setErrorStartAKE(boolean value); // // void setEnableAlways(boolean value); // // boolean getEnableAlways(); // // void setEnableManual(boolean value); // // boolean getEnableManual(); // } // // Path: src/main/java/net/java/otr4j/io/messages/AbstractMessage.java // public abstract class AbstractMessage { // // // Unencoded // public static final int MESSAGE_ERROR = 0xff; // public static final int MESSAGE_QUERY = 0x100; // public static final int MESSAGE_PLAINTEXT = 0x102; // // public int messageType; // // public AbstractMessage(int messageType) { // this.messageType = messageType; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + messageType; // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // AbstractMessage other = (AbstractMessage) obj; // if (messageType != other.messageType) // return false; // return true; // } // } // Path: src/main/java/net/java/otr4j/session/Session.java import java.math.BigInteger; import java.security.KeyPair; import java.security.PublicKey; import java.util.List; import net.java.otr4j.OtrEngineListener; import net.java.otr4j.OtrException; import net.java.otr4j.OtrPolicy; import net.java.otr4j.io.messages.AbstractMessage; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j.session; /** * @author George Politis */ public interface Session { interface OTRv { int ONE = 1; int TWO = 2; int THREE = 3; } SessionStatus getSessionStatus(); SessionID getSessionID(); void injectMessage(AbstractMessage m) throws OtrException; KeyPair getLocalKeyPair() throws OtrException; OtrPolicy getSessionPolicy(); String transformReceiving(String content) throws OtrException; String[] transformSending(String content, List<TLV> tlvs) throws OtrException; String[] transformSending(String content) throws OtrException; void startSession() throws OtrException; void endSession() throws OtrException; void refreshSession() throws OtrException; PublicKey getRemotePublicKey();
void addOtrEngineListener(OtrEngineListener l);
jitsi/otr4j
src/main/java/net/java/otr4j/OtrKeyManager.java
// Path: src/main/java/net/java/otr4j/session/SessionID.java // public final class SessionID { // // private final String accountID; // private final String userID; // private final String protocolName; // // public static final SessionID EMPTY = new SessionID(null, null, null); // /** @deprecated use {@link #EMPTY} instead */ // public static final SessionID Empty = EMPTY; // // public SessionID(String accountID, String userID, String protocolName) { // this.accountID = accountID; // this.userID = userID; // this.protocolName = protocolName; // } // // public String getAccountID() { // return accountID; // } // // public String getUserID() { // return userID; // } // // public String getProtocolName() { // return protocolName; // } // // @Override // public String toString() { // return accountID + '_' + protocolName + '_' + userID; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result // + ((accountID == null) ? 0 : accountID.hashCode()); // result = prime * result // + ((protocolName == null) ? 0 : protocolName.hashCode()); // result = prime * result + ((userID == null) ? 0 : userID.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // SessionID other = (SessionID) obj; // if (accountID == null) { // if (other.accountID != null) // return false; // } else if (!accountID.equals(other.accountID)) // return false; // if (protocolName == null) { // if (other.protocolName != null) // return false; // } else if (!protocolName.equals(other.protocolName)) // return false; // if (userID == null) { // if (other.userID != null) // return false; // } else if (!userID.equals(other.userID)) // return false; // return true; // } // }
import java.security.KeyPair; import java.security.PublicKey; import net.java.otr4j.session.SessionID;
/* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j; /** * @author George Politis */ public interface OtrKeyManager { void addListener(OtrKeyManagerListener l); void removeListener(OtrKeyManagerListener l);
// Path: src/main/java/net/java/otr4j/session/SessionID.java // public final class SessionID { // // private final String accountID; // private final String userID; // private final String protocolName; // // public static final SessionID EMPTY = new SessionID(null, null, null); // /** @deprecated use {@link #EMPTY} instead */ // public static final SessionID Empty = EMPTY; // // public SessionID(String accountID, String userID, String protocolName) { // this.accountID = accountID; // this.userID = userID; // this.protocolName = protocolName; // } // // public String getAccountID() { // return accountID; // } // // public String getUserID() { // return userID; // } // // public String getProtocolName() { // return protocolName; // } // // @Override // public String toString() { // return accountID + '_' + protocolName + '_' + userID; // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result // + ((accountID == null) ? 0 : accountID.hashCode()); // result = prime * result // + ((protocolName == null) ? 0 : protocolName.hashCode()); // result = prime * result + ((userID == null) ? 0 : userID.hashCode()); // return result; // } // // @Override // public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; // SessionID other = (SessionID) obj; // if (accountID == null) { // if (other.accountID != null) // return false; // } else if (!accountID.equals(other.accountID)) // return false; // if (protocolName == null) { // if (other.protocolName != null) // return false; // } else if (!protocolName.equals(other.protocolName)) // return false; // if (userID == null) { // if (other.userID != null) // return false; // } else if (!userID.equals(other.userID)) // return false; // return true; // } // } // Path: src/main/java/net/java/otr4j/OtrKeyManager.java import java.security.KeyPair; import java.security.PublicKey; import net.java.otr4j.session.SessionID; /* * Copyright @ 2015 Atlassian Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.java.otr4j; /** * @author George Politis */ public interface OtrKeyManager { void addListener(OtrKeyManagerListener l); void removeListener(OtrKeyManagerListener l);
void verify(SessionID sessionID);
peter-mount/filesystem
filesystem-core/src/test/java/onl/area51/filesystem/local/URITest.java
// Path: filesystem-core/src/test/java/onl/area51/filesystem/CommonTestUtils.java // public class CommonTestUtils // { // // private static final List<String> BODY = Arrays.asList( "test\n" ); // protected static final File BASE_FILE = new File( "target/filesystems" ).getAbsoluteFile(); // protected static final Path BASE_PATH = BASE_FILE.toPath().toAbsolutePath(); // // public static File getFile( String authority ) // { // return new File( BASE_FILE, authority ); // } // // public static void write( URI uri ) // throws IOException // { // write( Paths.get( uri ) ); // } // // public static void write( Path p ) // { // try // { // Files.write( p, BODY, StandardOpenOption.CREATE, StandardOpenOption.WRITE ); // } catch( IOException ex ) // { // throw new UncheckedIOException( ex ); // } // } // // public static void createFiles( Path parent, String prefix, int count ) // throws IOException // { // createFiles( parent, prefix, count, ".txt" ); // } // // public static void createFiles( Path parent, String prefix, int count, String suffix ) // throws IOException // { // createFiles( parent, prefix, 0, count, suffix ); // } // // public static void createFiles( Path parent, String prefix, int start, int end, String suffix ) // throws IOException // { // IntStream.range( start, end ) // .mapToObj( i -> prefix + i + suffix ) // .map( parent::resolve ) // .forEach( CommonTestUtils::write ); // } // // } // // Path: filesystem-core/src/test/java/onl/area51/filesystem/CommonTestUtils.java // public static void write( URI uri ) // throws IOException // { // write( Paths.get( uri ) ); // }
import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.util.Collections; import onl.area51.filesystem.CommonTestUtils; import static onl.area51.filesystem.CommonTestUtils.write; import org.junit.Assert; import static org.junit.Assert.assertFalse; import org.junit.Test;
/* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.local; /** * Test we can pass environment details via the URI's query parameters * * @author peter */ public class URITest extends CommonTestUtils { @Test public void uri() throws IOException { String authority = "uri.tryresource"; File delFS = getFile( authority ); URI uri = URI.create( "cache://" + authority + "?deleteOnExit=true&baseDirectory=" + delFS.toString() ); try( FileSystem fs = FileSystems.newFileSystem( uri, Collections.emptyMap() ) ) {
// Path: filesystem-core/src/test/java/onl/area51/filesystem/CommonTestUtils.java // public class CommonTestUtils // { // // private static final List<String> BODY = Arrays.asList( "test\n" ); // protected static final File BASE_FILE = new File( "target/filesystems" ).getAbsoluteFile(); // protected static final Path BASE_PATH = BASE_FILE.toPath().toAbsolutePath(); // // public static File getFile( String authority ) // { // return new File( BASE_FILE, authority ); // } // // public static void write( URI uri ) // throws IOException // { // write( Paths.get( uri ) ); // } // // public static void write( Path p ) // { // try // { // Files.write( p, BODY, StandardOpenOption.CREATE, StandardOpenOption.WRITE ); // } catch( IOException ex ) // { // throw new UncheckedIOException( ex ); // } // } // // public static void createFiles( Path parent, String prefix, int count ) // throws IOException // { // createFiles( parent, prefix, count, ".txt" ); // } // // public static void createFiles( Path parent, String prefix, int count, String suffix ) // throws IOException // { // createFiles( parent, prefix, 0, count, suffix ); // } // // public static void createFiles( Path parent, String prefix, int start, int end, String suffix ) // throws IOException // { // IntStream.range( start, end ) // .mapToObj( i -> prefix + i + suffix ) // .map( parent::resolve ) // .forEach( CommonTestUtils::write ); // } // // } // // Path: filesystem-core/src/test/java/onl/area51/filesystem/CommonTestUtils.java // public static void write( URI uri ) // throws IOException // { // write( Paths.get( uri ) ); // } // Path: filesystem-core/src/test/java/onl/area51/filesystem/local/URITest.java import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.util.Collections; import onl.area51.filesystem.CommonTestUtils; import static onl.area51.filesystem.CommonTestUtils.write; import org.junit.Assert; import static org.junit.Assert.assertFalse; import org.junit.Test; /* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.local; /** * Test we can pass environment details via the URI's query parameters * * @author peter */ public class URITest extends CommonTestUtils { @Test public void uri() throws IOException { String authority = "uri.tryresource"; File delFS = getFile( authority ); URI uri = URI.create( "cache://" + authority + "?deleteOnExit=true&baseDirectory=" + delFS.toString() ); try( FileSystem fs = FileSystems.newFileSystem( uri, Collections.emptyMap() ) ) {
write( fs.getPath( "/file1.txt" ) );
peter-mount/filesystem
filesystem-core/src/main/java/onl/area51/filesystem/local/LocalFileSystem.java
// Path: filesystem-core/src/main/java/onl/area51/filesystem/io/FileSystemIO.java // public interface FileSystemIO // extends Closeable // { // // /** // * The local base directory of the filesystem. For non-local filesystems, i.e. those who have no local storage this may be // * null. // * // * @return // */ // Path getBaseDirectory(); // // /** // * Is the filesystem temporary // * // * @return // */ // default boolean isTemporary() // { // return false; // } // // /** // * Returns a {@link Path} within the base directory for a Path // * // * @param path // * // * @return // * // * @throws IOException // */ // Path toPath( char[] path ) // throws IOException; // // /** // * Does the path exist in the filesystem // * // * @param path // * // * @return // * // * @throws IOException // */ // boolean exists( char path[] ) // throws IOException; // // /** // * Create a directory // * // * @param path // * @param attrs // * // * @throws IOException // */ // void createDirectory( char path[], FileAttribute<?> attrs[] ) // throws IOException; // // /** // * Create an InputStream for a path // * // * @param path // * // * @return // * // * @throws IOException on error // * @throws FileNotFoundException if the path does not exist // */ // InputStream newInputStream( char path[] ) // throws IOException; // // /** // * Create an output stream for a path // * // * @param path // * @param options // * // * @return // * // * @throws IOException // */ // OutputStream newOutputStream( char path[], OpenOption... options ) // throws IOException; // // /** // * Delete a path // * // * @param path // * @param exists // * // * @throws IOException // */ // void deleteFile( char path[], boolean exists ) // throws IOException; // // /** // * Is the Path a file // * // * @param path // * // * @return // * // * @throws IOException // */ // boolean isFile( char path[] ) // throws IOException; // // /** // * Is the path a directory // * // * @param path // * // * @return // * // * @throws IOException // */ // boolean isDirectory( char path[] ) // throws IOException; // // /** // * Create a ByteChannel // * // * @param path // * @param options // * @param attrs // * // * @return // * // * @throws IOException // */ // SeekableByteChannel newByteChannel( char path[], Set<? extends OpenOption> options, FileAttribute<?>... attrs ) // throws IOException; // // /** // * Create a FileChannel // * // * @param path // * @param options // * @param attrs // * // * @return // * // * @throws IOException // */ // FileChannel newFileChannel( char path[], Set<? extends OpenOption> options, FileAttribute<?>... attrs ) // throws IOException; // // /** // * Copy a file. Both src and dest must be paths within this filesystem // * // * @param b // * @param src // * @param dest // * @param options // * // * @throws IOException // */ // void copyFile( boolean b, char src[], char dest[], CopyOption... options ) // throws IOException; // // /** // * Get the attributes for a path // * // * @param path // * // * @return // * // * @throws IOException // */ // BasicFileAttributes getAttributes( char path[] ) // throws IOException; // // /** // * Get an attribute view of a path // * // * @param path // * // * @return // */ // BasicFileAttributeView getAttributeView( char path[] ); // // /** // * Get a directory stream for a path // * // * @param path // * @param filter // * // * @return // * // * @throws IOException // */ // DirectoryStream<Path> newDirectoryStream( char path[], Filter<? super Path> filter ) // throws IOException; // // /** // * If present represents the directory base for this FileSystem // */ // public static final String BASE_DIRECTORY = "baseDirectory"; // // /** // * Flag that if present on a file system's environment then the file system is temporary and will be destroyed when the vm // * exists or is closed // */ // public static final String DELETE_ON_EXIT = "deleteOnExit"; // // /** // * For caches, trigger an expire run // */ // default void expire() // { // } // // /** // * The length of the file at a path // * // * @param path // * // * @return // * // * @throws IOException if the path does not exist or is a directory // */ // long size( char[] path ) // throws IOException; // }
import java.io.IOException; import java.net.URI; import java.nio.file.Path; import java.util.Map; import java.util.function.BiFunction; import onl.area51.filesystem.io.FileSystemIO;
/* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.local; /** * A FileSystem built on a zip file * * @author Xueming Shen */ public class LocalFileSystem extends AbstractLocalFileSystem<LocalFileSystem, LocalPath, LocalFileStore> {
// Path: filesystem-core/src/main/java/onl/area51/filesystem/io/FileSystemIO.java // public interface FileSystemIO // extends Closeable // { // // /** // * The local base directory of the filesystem. For non-local filesystems, i.e. those who have no local storage this may be // * null. // * // * @return // */ // Path getBaseDirectory(); // // /** // * Is the filesystem temporary // * // * @return // */ // default boolean isTemporary() // { // return false; // } // // /** // * Returns a {@link Path} within the base directory for a Path // * // * @param path // * // * @return // * // * @throws IOException // */ // Path toPath( char[] path ) // throws IOException; // // /** // * Does the path exist in the filesystem // * // * @param path // * // * @return // * // * @throws IOException // */ // boolean exists( char path[] ) // throws IOException; // // /** // * Create a directory // * // * @param path // * @param attrs // * // * @throws IOException // */ // void createDirectory( char path[], FileAttribute<?> attrs[] ) // throws IOException; // // /** // * Create an InputStream for a path // * // * @param path // * // * @return // * // * @throws IOException on error // * @throws FileNotFoundException if the path does not exist // */ // InputStream newInputStream( char path[] ) // throws IOException; // // /** // * Create an output stream for a path // * // * @param path // * @param options // * // * @return // * // * @throws IOException // */ // OutputStream newOutputStream( char path[], OpenOption... options ) // throws IOException; // // /** // * Delete a path // * // * @param path // * @param exists // * // * @throws IOException // */ // void deleteFile( char path[], boolean exists ) // throws IOException; // // /** // * Is the Path a file // * // * @param path // * // * @return // * // * @throws IOException // */ // boolean isFile( char path[] ) // throws IOException; // // /** // * Is the path a directory // * // * @param path // * // * @return // * // * @throws IOException // */ // boolean isDirectory( char path[] ) // throws IOException; // // /** // * Create a ByteChannel // * // * @param path // * @param options // * @param attrs // * // * @return // * // * @throws IOException // */ // SeekableByteChannel newByteChannel( char path[], Set<? extends OpenOption> options, FileAttribute<?>... attrs ) // throws IOException; // // /** // * Create a FileChannel // * // * @param path // * @param options // * @param attrs // * // * @return // * // * @throws IOException // */ // FileChannel newFileChannel( char path[], Set<? extends OpenOption> options, FileAttribute<?>... attrs ) // throws IOException; // // /** // * Copy a file. Both src and dest must be paths within this filesystem // * // * @param b // * @param src // * @param dest // * @param options // * // * @throws IOException // */ // void copyFile( boolean b, char src[], char dest[], CopyOption... options ) // throws IOException; // // /** // * Get the attributes for a path // * // * @param path // * // * @return // * // * @throws IOException // */ // BasicFileAttributes getAttributes( char path[] ) // throws IOException; // // /** // * Get an attribute view of a path // * // * @param path // * // * @return // */ // BasicFileAttributeView getAttributeView( char path[] ); // // /** // * Get a directory stream for a path // * // * @param path // * @param filter // * // * @return // * // * @throws IOException // */ // DirectoryStream<Path> newDirectoryStream( char path[], Filter<? super Path> filter ) // throws IOException; // // /** // * If present represents the directory base for this FileSystem // */ // public static final String BASE_DIRECTORY = "baseDirectory"; // // /** // * Flag that if present on a file system's environment then the file system is temporary and will be destroyed when the vm // * exists or is closed // */ // public static final String DELETE_ON_EXIT = "deleteOnExit"; // // /** // * For caches, trigger an expire run // */ // default void expire() // { // } // // /** // * The length of the file at a path // * // * @param path // * // * @return // * // * @throws IOException if the path does not exist or is a directory // */ // long size( char[] path ) // throws IOException; // } // Path: filesystem-core/src/main/java/onl/area51/filesystem/local/LocalFileSystem.java import java.io.IOException; import java.net.URI; import java.nio.file.Path; import java.util.Map; import java.util.function.BiFunction; import onl.area51.filesystem.io.FileSystemIO; /* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.local; /** * A FileSystem built on a zip file * * @author Xueming Shen */ public class LocalFileSystem extends AbstractLocalFileSystem<LocalFileSystem, LocalPath, LocalFileStore> {
LocalFileSystem( URI uri, LocalFileSystemProvider provider, Path cachePath, Map<String, Object> env, BiFunction<Path, Map<String, ?>, FileSystemIO> fileSystemIO )
peter-mount/filesystem
filesystem-memory/src/main/java/onl/area51/filesystem/memory/MemoryFileSystemProvider.java
// Path: filesystem-core/src/main/java/onl/area51/filesystem/AbstractFileSystemProvider.java // public abstract class AbstractFileSystemProvider<F extends AbstractFileSystem<F, P, ?>, P extends AbstractPath<F, P>> // extends FileSystemProvider // { // // private final Map<URI, F> filesystems = new ConcurrentHashMap<>(); // // @Override // public abstract String getScheme(); // // protected final Path uriToPath( URI uri ) // throws IOException // { // String scheme = uri.getScheme(); // if( (scheme == null) || !scheme.equalsIgnoreCase( getScheme() ) ) { // throw new IllegalArgumentException( "URI scheme is not '" + getScheme() + "'" ); // } // // Path path = FileSystemUtils.getCacheDirectory() // .resolve( getScheme() ) // .resolve( uri.getAuthority() ) // .toAbsolutePath(); // // Files.createDirectories( path ); // // return path; // } // // protected abstract F createFileSystem( URI uri, Path p, Map<String, Object> env ) // throws IOException; // // private F createFileSystem( URI uri, Map<String, Object> env ) // { // try { // return createFileSystem( uri, uriToPath( uri ).toRealPath(), env ); // } // catch( IOException ex ) { // throw new UncheckedIOException( ex ); // } // } // // @Override // public final FileSystem newFileSystem( URI uri, Map<String, ?> env ) // throws IOException // { // return filesystems.computeIfAbsent( FileSystemUtils.getFileSystemURI( uri ), // fsUri -> createFileSystem(fsUri, (Map<String, Object>) FileSystemUtils.getFileSystemEnv( uri, env )) ); // } // // public final void deleteFileSystem( FileSystem fs ) // { // if( fs instanceof AbstractFileSystem ) { // filesystems.remove( ((AbstractFileSystem) fs).getUri() ); // } // } // // @Override // public final FileSystem newFileSystem( Path path, Map<String, ?> env ) // throws IOException // { // if( path.getFileSystem() != FileSystems.getDefault() ) { // throw new UnsupportedOperationException(); // } // // Files.createDirectories( path ); // return createFileSystem(path.toUri(), path, (Map<String, Object>) env); // } // // @Override // public final Path getPath( URI uri ) // { // return getFileSystem( uri ).getPath( uri.getPath() ); // } // // @Override // public final FileSystem getFileSystem( URI uri ) // { // URI fsUri = FileSystemUtils.getFileSystemURI( uri ); // try { // return newFileSystem( uri, new HashMap<>() ); // } // catch( IOException ex ) { // throw new FileSystemNotFoundException( fsUri.toString() ); // } // } // } // // Path: filesystem-core/src/main/java/onl/area51/filesystem/io/Flat.java // @MetaInfServices(FileSystemIO.class) // public class Flat // extends LocalFileSystemIO // { // // public Flat( Path basePath, // Map<String, ?> env ) // { // super( basePath, env ); // } // // @Override // protected String getPath( char[] path ) // throws IOException // { // return String.valueOf( path ); // } // // }
import java.io.IOException; import java.net.URI; import java.nio.channels.SeekableByteChannel; import java.nio.file.AccessMode; import java.nio.file.CopyOption; import java.nio.file.DirectoryStream; import java.nio.file.FileStore; import java.nio.file.LinkOption; import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.ProviderMismatchException; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttributeView; import java.nio.file.spi.FileSystemProvider; import java.util.Map; import java.util.Objects; import java.util.Set; import onl.area51.filesystem.AbstractFileSystemProvider; import onl.area51.filesystem.io.Flat; import org.kohsuke.MetaInfServices;
/* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.memory; /** * * @author peter */ @MetaInfServices(FileSystemProvider.class) public class MemoryFileSystemProvider
// Path: filesystem-core/src/main/java/onl/area51/filesystem/AbstractFileSystemProvider.java // public abstract class AbstractFileSystemProvider<F extends AbstractFileSystem<F, P, ?>, P extends AbstractPath<F, P>> // extends FileSystemProvider // { // // private final Map<URI, F> filesystems = new ConcurrentHashMap<>(); // // @Override // public abstract String getScheme(); // // protected final Path uriToPath( URI uri ) // throws IOException // { // String scheme = uri.getScheme(); // if( (scheme == null) || !scheme.equalsIgnoreCase( getScheme() ) ) { // throw new IllegalArgumentException( "URI scheme is not '" + getScheme() + "'" ); // } // // Path path = FileSystemUtils.getCacheDirectory() // .resolve( getScheme() ) // .resolve( uri.getAuthority() ) // .toAbsolutePath(); // // Files.createDirectories( path ); // // return path; // } // // protected abstract F createFileSystem( URI uri, Path p, Map<String, Object> env ) // throws IOException; // // private F createFileSystem( URI uri, Map<String, Object> env ) // { // try { // return createFileSystem( uri, uriToPath( uri ).toRealPath(), env ); // } // catch( IOException ex ) { // throw new UncheckedIOException( ex ); // } // } // // @Override // public final FileSystem newFileSystem( URI uri, Map<String, ?> env ) // throws IOException // { // return filesystems.computeIfAbsent( FileSystemUtils.getFileSystemURI( uri ), // fsUri -> createFileSystem(fsUri, (Map<String, Object>) FileSystemUtils.getFileSystemEnv( uri, env )) ); // } // // public final void deleteFileSystem( FileSystem fs ) // { // if( fs instanceof AbstractFileSystem ) { // filesystems.remove( ((AbstractFileSystem) fs).getUri() ); // } // } // // @Override // public final FileSystem newFileSystem( Path path, Map<String, ?> env ) // throws IOException // { // if( path.getFileSystem() != FileSystems.getDefault() ) { // throw new UnsupportedOperationException(); // } // // Files.createDirectories( path ); // return createFileSystem(path.toUri(), path, (Map<String, Object>) env); // } // // @Override // public final Path getPath( URI uri ) // { // return getFileSystem( uri ).getPath( uri.getPath() ); // } // // @Override // public final FileSystem getFileSystem( URI uri ) // { // URI fsUri = FileSystemUtils.getFileSystemURI( uri ); // try { // return newFileSystem( uri, new HashMap<>() ); // } // catch( IOException ex ) { // throw new FileSystemNotFoundException( fsUri.toString() ); // } // } // } // // Path: filesystem-core/src/main/java/onl/area51/filesystem/io/Flat.java // @MetaInfServices(FileSystemIO.class) // public class Flat // extends LocalFileSystemIO // { // // public Flat( Path basePath, // Map<String, ?> env ) // { // super( basePath, env ); // } // // @Override // protected String getPath( char[] path ) // throws IOException // { // return String.valueOf( path ); // } // // } // Path: filesystem-memory/src/main/java/onl/area51/filesystem/memory/MemoryFileSystemProvider.java import java.io.IOException; import java.net.URI; import java.nio.channels.SeekableByteChannel; import java.nio.file.AccessMode; import java.nio.file.CopyOption; import java.nio.file.DirectoryStream; import java.nio.file.FileStore; import java.nio.file.LinkOption; import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.ProviderMismatchException; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttributeView; import java.nio.file.spi.FileSystemProvider; import java.util.Map; import java.util.Objects; import java.util.Set; import onl.area51.filesystem.AbstractFileSystemProvider; import onl.area51.filesystem.io.Flat; import org.kohsuke.MetaInfServices; /* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.memory; /** * * @author peter */ @MetaInfServices(FileSystemProvider.class) public class MemoryFileSystemProvider
extends AbstractFileSystemProvider<MemoryFileSystem, MemoryPath>
peter-mount/filesystem
filesystem-memory/src/main/java/onl/area51/filesystem/memory/MemoryFileSystemProvider.java
// Path: filesystem-core/src/main/java/onl/area51/filesystem/AbstractFileSystemProvider.java // public abstract class AbstractFileSystemProvider<F extends AbstractFileSystem<F, P, ?>, P extends AbstractPath<F, P>> // extends FileSystemProvider // { // // private final Map<URI, F> filesystems = new ConcurrentHashMap<>(); // // @Override // public abstract String getScheme(); // // protected final Path uriToPath( URI uri ) // throws IOException // { // String scheme = uri.getScheme(); // if( (scheme == null) || !scheme.equalsIgnoreCase( getScheme() ) ) { // throw new IllegalArgumentException( "URI scheme is not '" + getScheme() + "'" ); // } // // Path path = FileSystemUtils.getCacheDirectory() // .resolve( getScheme() ) // .resolve( uri.getAuthority() ) // .toAbsolutePath(); // // Files.createDirectories( path ); // // return path; // } // // protected abstract F createFileSystem( URI uri, Path p, Map<String, Object> env ) // throws IOException; // // private F createFileSystem( URI uri, Map<String, Object> env ) // { // try { // return createFileSystem( uri, uriToPath( uri ).toRealPath(), env ); // } // catch( IOException ex ) { // throw new UncheckedIOException( ex ); // } // } // // @Override // public final FileSystem newFileSystem( URI uri, Map<String, ?> env ) // throws IOException // { // return filesystems.computeIfAbsent( FileSystemUtils.getFileSystemURI( uri ), // fsUri -> createFileSystem(fsUri, (Map<String, Object>) FileSystemUtils.getFileSystemEnv( uri, env )) ); // } // // public final void deleteFileSystem( FileSystem fs ) // { // if( fs instanceof AbstractFileSystem ) { // filesystems.remove( ((AbstractFileSystem) fs).getUri() ); // } // } // // @Override // public final FileSystem newFileSystem( Path path, Map<String, ?> env ) // throws IOException // { // if( path.getFileSystem() != FileSystems.getDefault() ) { // throw new UnsupportedOperationException(); // } // // Files.createDirectories( path ); // return createFileSystem(path.toUri(), path, (Map<String, Object>) env); // } // // @Override // public final Path getPath( URI uri ) // { // return getFileSystem( uri ).getPath( uri.getPath() ); // } // // @Override // public final FileSystem getFileSystem( URI uri ) // { // URI fsUri = FileSystemUtils.getFileSystemURI( uri ); // try { // return newFileSystem( uri, new HashMap<>() ); // } // catch( IOException ex ) { // throw new FileSystemNotFoundException( fsUri.toString() ); // } // } // } // // Path: filesystem-core/src/main/java/onl/area51/filesystem/io/Flat.java // @MetaInfServices(FileSystemIO.class) // public class Flat // extends LocalFileSystemIO // { // // public Flat( Path basePath, // Map<String, ?> env ) // { // super( basePath, env ); // } // // @Override // protected String getPath( char[] path ) // throws IOException // { // return String.valueOf( path ); // } // // }
import java.io.IOException; import java.net.URI; import java.nio.channels.SeekableByteChannel; import java.nio.file.AccessMode; import java.nio.file.CopyOption; import java.nio.file.DirectoryStream; import java.nio.file.FileStore; import java.nio.file.LinkOption; import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.ProviderMismatchException; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttributeView; import java.nio.file.spi.FileSystemProvider; import java.util.Map; import java.util.Objects; import java.util.Set; import onl.area51.filesystem.AbstractFileSystemProvider; import onl.area51.filesystem.io.Flat; import org.kohsuke.MetaInfServices;
/* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.memory; /** * * @author peter */ @MetaInfServices(FileSystemProvider.class) public class MemoryFileSystemProvider extends AbstractFileSystemProvider<MemoryFileSystem, MemoryPath> { @Override public String getScheme() { return "memory"; } @Override protected MemoryFileSystem createFileSystem( URI uri, Path p, Map<String, Object> env ) throws IOException {
// Path: filesystem-core/src/main/java/onl/area51/filesystem/AbstractFileSystemProvider.java // public abstract class AbstractFileSystemProvider<F extends AbstractFileSystem<F, P, ?>, P extends AbstractPath<F, P>> // extends FileSystemProvider // { // // private final Map<URI, F> filesystems = new ConcurrentHashMap<>(); // // @Override // public abstract String getScheme(); // // protected final Path uriToPath( URI uri ) // throws IOException // { // String scheme = uri.getScheme(); // if( (scheme == null) || !scheme.equalsIgnoreCase( getScheme() ) ) { // throw new IllegalArgumentException( "URI scheme is not '" + getScheme() + "'" ); // } // // Path path = FileSystemUtils.getCacheDirectory() // .resolve( getScheme() ) // .resolve( uri.getAuthority() ) // .toAbsolutePath(); // // Files.createDirectories( path ); // // return path; // } // // protected abstract F createFileSystem( URI uri, Path p, Map<String, Object> env ) // throws IOException; // // private F createFileSystem( URI uri, Map<String, Object> env ) // { // try { // return createFileSystem( uri, uriToPath( uri ).toRealPath(), env ); // } // catch( IOException ex ) { // throw new UncheckedIOException( ex ); // } // } // // @Override // public final FileSystem newFileSystem( URI uri, Map<String, ?> env ) // throws IOException // { // return filesystems.computeIfAbsent( FileSystemUtils.getFileSystemURI( uri ), // fsUri -> createFileSystem(fsUri, (Map<String, Object>) FileSystemUtils.getFileSystemEnv( uri, env )) ); // } // // public final void deleteFileSystem( FileSystem fs ) // { // if( fs instanceof AbstractFileSystem ) { // filesystems.remove( ((AbstractFileSystem) fs).getUri() ); // } // } // // @Override // public final FileSystem newFileSystem( Path path, Map<String, ?> env ) // throws IOException // { // if( path.getFileSystem() != FileSystems.getDefault() ) { // throw new UnsupportedOperationException(); // } // // Files.createDirectories( path ); // return createFileSystem(path.toUri(), path, (Map<String, Object>) env); // } // // @Override // public final Path getPath( URI uri ) // { // return getFileSystem( uri ).getPath( uri.getPath() ); // } // // @Override // public final FileSystem getFileSystem( URI uri ) // { // URI fsUri = FileSystemUtils.getFileSystemURI( uri ); // try { // return newFileSystem( uri, new HashMap<>() ); // } // catch( IOException ex ) { // throw new FileSystemNotFoundException( fsUri.toString() ); // } // } // } // // Path: filesystem-core/src/main/java/onl/area51/filesystem/io/Flat.java // @MetaInfServices(FileSystemIO.class) // public class Flat // extends LocalFileSystemIO // { // // public Flat( Path basePath, // Map<String, ?> env ) // { // super( basePath, env ); // } // // @Override // protected String getPath( char[] path ) // throws IOException // { // return String.valueOf( path ); // } // // } // Path: filesystem-memory/src/main/java/onl/area51/filesystem/memory/MemoryFileSystemProvider.java import java.io.IOException; import java.net.URI; import java.nio.channels.SeekableByteChannel; import java.nio.file.AccessMode; import java.nio.file.CopyOption; import java.nio.file.DirectoryStream; import java.nio.file.FileStore; import java.nio.file.LinkOption; import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.ProviderMismatchException; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttributeView; import java.nio.file.spi.FileSystemProvider; import java.util.Map; import java.util.Objects; import java.util.Set; import onl.area51.filesystem.AbstractFileSystemProvider; import onl.area51.filesystem.io.Flat; import org.kohsuke.MetaInfServices; /* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.memory; /** * * @author peter */ @MetaInfServices(FileSystemProvider.class) public class MemoryFileSystemProvider extends AbstractFileSystemProvider<MemoryFileSystem, MemoryPath> { @Override public String getScheme() { return "memory"; } @Override protected MemoryFileSystem createFileSystem( URI uri, Path p, Map<String, Object> env ) throws IOException {
return new MemoryFileSystem( uri, this, p, env, Flat::new );
peter-mount/filesystem
filesystem-core/src/main/java/onl/area51/filesystem/local/LocalFileSystemProvider.java
// Path: filesystem-core/src/main/java/onl/area51/filesystem/io/Flat.java // @MetaInfServices(FileSystemIO.class) // public class Flat // extends LocalFileSystemIO // { // // public Flat( Path basePath, // Map<String, ?> env ) // { // super( basePath, env ); // } // // @Override // protected String getPath( char[] path ) // throws IOException // { // return String.valueOf( path ); // } // // }
import java.io.IOException; import java.net.URI; import java.nio.file.Path; import java.nio.file.ProviderMismatchException; import java.nio.file.spi.FileSystemProvider; import java.util.Map; import java.util.Objects; import onl.area51.filesystem.io.Flat; import org.kohsuke.MetaInfServices;
/* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.local; /** * * @author peter */ @MetaInfServices(FileSystemProvider.class) public class LocalFileSystemProvider extends AbstractLocalFileSystemProvider<LocalFileSystem, LocalPath> { @Override public String getScheme() { return "local"; } @Override protected LocalFileSystem createFileSystem( URI uri, Path p, Map<String, Object> env ) throws IOException {
// Path: filesystem-core/src/main/java/onl/area51/filesystem/io/Flat.java // @MetaInfServices(FileSystemIO.class) // public class Flat // extends LocalFileSystemIO // { // // public Flat( Path basePath, // Map<String, ?> env ) // { // super( basePath, env ); // } // // @Override // protected String getPath( char[] path ) // throws IOException // { // return String.valueOf( path ); // } // // } // Path: filesystem-core/src/main/java/onl/area51/filesystem/local/LocalFileSystemProvider.java import java.io.IOException; import java.net.URI; import java.nio.file.Path; import java.nio.file.ProviderMismatchException; import java.nio.file.spi.FileSystemProvider; import java.util.Map; import java.util.Objects; import onl.area51.filesystem.io.Flat; import org.kohsuke.MetaInfServices; /* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.local; /** * * @author peter */ @MetaInfServices(FileSystemProvider.class) public class LocalFileSystemProvider extends AbstractLocalFileSystemProvider<LocalFileSystem, LocalPath> { @Override public String getScheme() { return "local"; } @Override protected LocalFileSystem createFileSystem( URI uri, Path p, Map<String, Object> env ) throws IOException {
return new LocalFileSystem( uri, this, p, env, Flat::new );
peter-mount/filesystem
filesystem-ftp/src/test/java/onl/area51/filesystem/http/HttpTest.java
// Path: filesystem-core/src/main/java/onl/area51/filesystem/cache/CacheFileSystemProvider.java // @MetaInfServices(FileSystemProvider.class) // public class CacheFileSystemProvider // extends AbstractLocalFileSystemProvider<CacheFileSystem, CachePath> // { // // @Override // public String getScheme() // { // return "cache"; // } // // @Override // protected CacheFileSystem createFileSystem( URI uri, Path p, Map<String, Object> env ) // throws IOException // { // return new CacheFileSystem( uri, this, p, env, FileSystemIORepository::create ); // } // // @Override // protected CachePath toCachePath( Path path ) // { // Objects.requireNonNull( path ); // if( !(path instanceof CachePath) ) { // throw new ProviderMismatchException(); // } // return (CachePath) path.toAbsolutePath(); // } // }
import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import onl.area51.filesystem.cache.CacheFileSystemProvider; import org.junit.BeforeClass; import org.junit.Test; import uk.trainwatch.util.MapBuilder;
/* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.http; /** * * @author peter */ public class HttpTest extends CommonTestUtils { private static final String HTTP_PREFIX = "cache://http.test"; private static final String HTTPS_PREFIX = "cache://https.test"; @BeforeClass public static void setUpClass() throws IOException {
// Path: filesystem-core/src/main/java/onl/area51/filesystem/cache/CacheFileSystemProvider.java // @MetaInfServices(FileSystemProvider.class) // public class CacheFileSystemProvider // extends AbstractLocalFileSystemProvider<CacheFileSystem, CachePath> // { // // @Override // public String getScheme() // { // return "cache"; // } // // @Override // protected CacheFileSystem createFileSystem( URI uri, Path p, Map<String, Object> env ) // throws IOException // { // return new CacheFileSystem( uri, this, p, env, FileSystemIORepository::create ); // } // // @Override // protected CachePath toCachePath( Path path ) // { // Objects.requireNonNull( path ); // if( !(path instanceof CachePath) ) { // throw new ProviderMismatchException(); // } // return (CachePath) path.toAbsolutePath(); // } // } // Path: filesystem-ftp/src/test/java/onl/area51/filesystem/http/HttpTest.java import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import onl.area51.filesystem.cache.CacheFileSystemProvider; import org.junit.BeforeClass; import org.junit.Test; import uk.trainwatch.util.MapBuilder; /* * Copyright 2016 peter. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package onl.area51.filesystem.http; /** * * @author peter */ public class HttpTest extends CommonTestUtils { private static final String HTTP_PREFIX = "cache://http.test"; private static final String HTTPS_PREFIX = "cache://https.test"; @BeforeClass public static void setUpClass() throws IOException {
System.setProperty( CacheFileSystemProvider.class.getName(), BASE_FILE.toString() );
google/safe-html-types
types/src/test/java/com/google/common/html/types/TrustedResourceUrlBuilderTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible;
// **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/TrustedResourceUrlBuilderTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link TrustedResourceUrlBuilder}. */ @GwtCompatible public class TrustedResourceUrlBuilderTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/TrustedResourceUrlBuilderTest.java import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; // **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/TrustedResourceUrlBuilderTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link TrustedResourceUrlBuilder}. */ @GwtCompatible public class TrustedResourceUrlBuilderTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
assertClassIsNotExportable(TrustedResourceUrlBuilder.class);
google/safe-html-types
types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() {
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() {
assertClassIsNotExportable(UncheckedConversions.class);
google/safe-html-types
types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() { assertClassIsNotExportable(UncheckedConversions.class); } public void testSafeHtmlFromStringKnownToSatisfyTypeContract() { String html = "<script>this is not valid SafeHtml"; assertEquals( html,
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() { assertClassIsNotExportable(UncheckedConversions.class); } public void testSafeHtmlFromStringKnownToSatisfyTypeContract() { String html = "<script>this is not valid SafeHtml"; assertEquals( html,
safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() { assertClassIsNotExportable(UncheckedConversions.class); } public void testSafeHtmlFromStringKnownToSatisfyTypeContract() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString()); } public void testSafeScriptFromStringKnownToSatisfyTypeContract() { String script = "invalid SafeScript"; assertEquals( script,
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() { assertClassIsNotExportable(UncheckedConversions.class); } public void testSafeHtmlFromStringKnownToSatisfyTypeContract() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString()); } public void testSafeScriptFromStringKnownToSatisfyTypeContract() { String script = "invalid SafeScript"; assertEquals( script,
safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() { assertClassIsNotExportable(UncheckedConversions.class); } public void testSafeHtmlFromStringKnownToSatisfyTypeContract() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString()); } public void testSafeScriptFromStringKnownToSatisfyTypeContract() { String script = "invalid SafeScript"; assertEquals( script, safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString()); } public void testSafeStyleFromStringKnownToSatisfyTypeContract() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style,
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() { assertClassIsNotExportable(UncheckedConversions.class); } public void testSafeHtmlFromStringKnownToSatisfyTypeContract() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString()); } public void testSafeScriptFromStringKnownToSatisfyTypeContract() { String script = "invalid SafeScript"; assertEquals( script, safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString()); } public void testSafeStyleFromStringKnownToSatisfyTypeContract() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style,
safeStyleFromStringKnownToSatisfyTypeContract(style).getSafeStyleString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() { assertClassIsNotExportable(UncheckedConversions.class); } public void testSafeHtmlFromStringKnownToSatisfyTypeContract() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString()); } public void testSafeScriptFromStringKnownToSatisfyTypeContract() { String script = "invalid SafeScript"; assertEquals( script, safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString()); } public void testSafeStyleFromStringKnownToSatisfyTypeContract() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, safeStyleFromStringKnownToSatisfyTypeContract(style).getSafeStyleString()); } public void testSafeStyleSheetFromStringKnownToSatisfyTypeContract() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet,
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link UncheckedConversions}. */ @GwtCompatible public class UncheckedConversionsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testNotExportable() { assertClassIsNotExportable(UncheckedConversions.class); } public void testSafeHtmlFromStringKnownToSatisfyTypeContract() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString()); } public void testSafeScriptFromStringKnownToSatisfyTypeContract() { String script = "invalid SafeScript"; assertEquals( script, safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString()); } public void testSafeStyleFromStringKnownToSatisfyTypeContract() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, safeStyleFromStringKnownToSatisfyTypeContract(style).getSafeStyleString()); } public void testSafeStyleSheetFromStringKnownToSatisfyTypeContract() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet,
safeStyleSheetFromStringKnownToSatisfyTypeContract(styleSheet).getSafeStyleSheetString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase;
assertEquals( html, safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString()); } public void testSafeScriptFromStringKnownToSatisfyTypeContract() { String script = "invalid SafeScript"; assertEquals( script, safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString()); } public void testSafeStyleFromStringKnownToSatisfyTypeContract() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, safeStyleFromStringKnownToSatisfyTypeContract(style).getSafeStyleString()); } public void testSafeStyleSheetFromStringKnownToSatisfyTypeContract() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet, safeStyleSheetFromStringKnownToSatisfyTypeContract(styleSheet).getSafeStyleSheetString()); } public void testSafeUrlFromStringKnownToSatisfyTypeContract() { String url = "data:this will not be sanitized"; assertEquals( url,
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; assertEquals( html, safeHtmlFromStringKnownToSatisfyTypeContract(html).getSafeHtmlString()); } public void testSafeScriptFromStringKnownToSatisfyTypeContract() { String script = "invalid SafeScript"; assertEquals( script, safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString()); } public void testSafeStyleFromStringKnownToSatisfyTypeContract() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, safeStyleFromStringKnownToSatisfyTypeContract(style).getSafeStyleString()); } public void testSafeStyleSheetFromStringKnownToSatisfyTypeContract() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet, safeStyleSheetFromStringKnownToSatisfyTypeContract(styleSheet).getSafeStyleSheetString()); } public void testSafeUrlFromStringKnownToSatisfyTypeContract() { String url = "data:this will not be sanitized"; assertEquals( url,
safeUrlFromStringKnownToSatisfyTypeContract(url).getSafeUrlString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase;
assertEquals( script, safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString()); } public void testSafeStyleFromStringKnownToSatisfyTypeContract() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, safeStyleFromStringKnownToSatisfyTypeContract(style).getSafeStyleString()); } public void testSafeStyleSheetFromStringKnownToSatisfyTypeContract() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet, safeStyleSheetFromStringKnownToSatisfyTypeContract(styleSheet).getSafeStyleSheetString()); } public void testSafeUrlFromStringKnownToSatisfyTypeContract() { String url = "data:this will not be sanitized"; assertEquals( url, safeUrlFromStringKnownToSatisfyTypeContract(url).getSafeUrlString()); } public void testTrustedResourceUrlFromStringKnownToSatisfyTypeContract() { String url = "data:this will not be sanitized"; assertEquals( url,
// Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeHtml safeHtmlFromStringKnownToSatisfyTypeContract(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeScript safeScriptFromStringKnownToSatisfyTypeContract(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyle safeStyleFromStringKnownToSatisfyTypeContract(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeStyleSheet safeStyleSheetFromStringKnownToSatisfyTypeContract( // String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static SafeUrl safeUrlFromStringKnownToSatisfyTypeContract(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/UncheckedConversions.java // public static TrustedResourceUrl trustedResourceUrlFromStringKnownToSatisfyTypeContract( // String url) { // return new TrustedResourceUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/UncheckedConversionsTest.java import static com.google.common.html.types.UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeScriptFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; assertEquals( script, safeScriptFromStringKnownToSatisfyTypeContract(script).getSafeScriptString()); } public void testSafeStyleFromStringKnownToSatisfyTypeContract() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, safeStyleFromStringKnownToSatisfyTypeContract(style).getSafeStyleString()); } public void testSafeStyleSheetFromStringKnownToSatisfyTypeContract() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet, safeStyleSheetFromStringKnownToSatisfyTypeContract(styleSheet).getSafeStyleSheetString()); } public void testSafeUrlFromStringKnownToSatisfyTypeContract() { String url = "data:this will not be sanitized"; assertEquals( url, safeUrlFromStringKnownToSatisfyTypeContract(url).getSafeUrlString()); } public void testTrustedResourceUrlFromStringKnownToSatisfyTypeContract() { String url = "data:this will not be sanitized"; assertEquals( url,
trustedResourceUrlFromStringKnownToSatisfyTypeContract(url).getTrustedResourceUrlString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeStyleTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeStyle newSafeStyleForTest(String string) { // return UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract(string); // }
import static com.google.common.html.types.testing.HtmlConversions.newSafeStyleForTest; import com.google.common.annotations.GwtCompatible; import com.google.common.testing.EqualsTester; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeStyle} and its factory methods. */ @GwtCompatible public class SafeStyleTest extends TestCase { // TODO(mlourenco): Remove usage newSafeStyleForTest once we have a GWT // version of builders. public void testToString_returnsDebugString() { assertEquals( "SafeStyle{width: 1em;}",
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeStyle newSafeStyleForTest(String string) { // return UncheckedConversions.safeStyleFromStringKnownToSatisfyTypeContract(string); // } // Path: types/src/test/java/com/google/common/html/types/SafeStyleTest.java import static com.google.common.html.types.testing.HtmlConversions.newSafeStyleForTest; import com.google.common.annotations.GwtCompatible; import com.google.common.testing.EqualsTester; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeStyle} and its factory methods. */ @GwtCompatible public class SafeStyleTest extends TestCase { // TODO(mlourenco): Remove usage newSafeStyleForTest once we have a GWT // version of builders. public void testToString_returnsDebugString() { assertEquals( "SafeStyle{width: 1em;}",
newSafeStyleForTest("width: 1em;").toString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeHtmlTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // }
import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import com.google.common.annotations.GwtCompatible; import com.google.common.testing.EqualsTester; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeHtml}. */ @GwtCompatible public class SafeHtmlTest extends TestCase { // TODO(mlourenco): Remove usage newSafeStyleForTest once we have a GWT // version of builders. public void testToString_returnsDebugString() { String html = "<b>Hello World</b>";
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // Path: types/src/test/java/com/google/common/html/types/SafeHtmlTest.java import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import com.google.common.annotations.GwtCompatible; import com.google.common.testing.EqualsTester; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeHtml}. */ @GwtCompatible public class SafeHtmlTest extends TestCase { // TODO(mlourenco): Remove usage newSafeStyleForTest once we have a GWT // version of builders. public void testToString_returnsDebugString() { String html = "<b>Hello World</b>";
assertEquals("SafeHtml{" + html + "}", newSafeHtmlForTest(html).toString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/TrustedResourceUrlTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static TrustedResourceUrl newTrustedResourceUrlForTest(String string) { // return UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract(string); // }
import static com.google.common.html.types.testing.HtmlConversions.newTrustedResourceUrlForTest; import com.google.common.annotations.GwtCompatible; import com.google.common.testing.EqualsTester; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link TrustedResourceUrl}. */ @GwtCompatible public class TrustedResourceUrlTest extends TestCase { // TODO(mlourenco): Remove usage newTrustedResourceUrlForTest once we have a GWT // version of builders. public void testToString_returnsDebugString() {
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static TrustedResourceUrl newTrustedResourceUrlForTest(String string) { // return UncheckedConversions.trustedResourceUrlFromStringKnownToSatisfyTypeContract(string); // } // Path: types/src/test/java/com/google/common/html/types/TrustedResourceUrlTest.java import static com.google.common.html.types.testing.HtmlConversions.newTrustedResourceUrlForTest; import com.google.common.annotations.GwtCompatible; import com.google.common.testing.EqualsTester; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link TrustedResourceUrl}. */ @GwtCompatible public class TrustedResourceUrlTest extends TestCase { // TODO(mlourenco): Remove usage newTrustedResourceUrlForTest once we have a GWT // version of builders. public void testToString_returnsDebugString() {
assertEquals("TrustedResourceUrl{url}", newTrustedResourceUrlForTest("url").toString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeHtmlsTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase;
// **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeHtmlsTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeHtmls}. */ @GwtCompatible public class SafeHtmlsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/SafeHtmlsTest.java import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; // **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeHtmlsTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeHtmls}. */ @GwtCompatible public class SafeHtmlsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
assertClassIsNotExportable(SafeHtmls.class);
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeHtmlsTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase;
public void testFromStyleSheet() { SafeHtml html = SafeHtmls.fromStyleSheet(SafeStyleSheets.fromConstant( ".title { color: #000000; };")); assertEquals( "<style type=\"text/css\">.title { color: #000000; };</style>", html.getSafeHtmlString()); } public void testFromStyleSheetIllegal() { SafeStyleSheet unsafeStyle = UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract( ".title { color: #000000; };</style><script>alert('malicious script');</script>"); try { SafeHtmls.fromStyleSheet(unsafeStyle); fail("Should throw an AssertionError if style contains \"<\" or \">\""); } catch (IllegalArgumentException e) { assertNotNull(e); } } public void testFromStyleUrl() { SafeHtml html = SafeHtmls.fromStyleUrl( TrustedResourceUrls.fromConstant("https://example.com/&<\"'style.css")); assertEquals("<style type=\"text/css\" " + "src=\"https://example.com/&amp;&lt;&quot;&#39;style.css\"></style>", html.getSafeHtmlString()); } public void testToAndFromProto() { String html = "<b>Hello World</b>";
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/SafeHtmlsTest.java import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; public void testFromStyleSheet() { SafeHtml html = SafeHtmls.fromStyleSheet(SafeStyleSheets.fromConstant( ".title { color: #000000; };")); assertEquals( "<style type=\"text/css\">.title { color: #000000; };</style>", html.getSafeHtmlString()); } public void testFromStyleSheetIllegal() { SafeStyleSheet unsafeStyle = UncheckedConversions.safeStyleSheetFromStringKnownToSatisfyTypeContract( ".title { color: #000000; };</style><script>alert('malicious script');</script>"); try { SafeHtmls.fromStyleSheet(unsafeStyle); fail("Should throw an AssertionError if style contains \"<\" or \">\""); } catch (IllegalArgumentException e) { assertNotNull(e); } } public void testFromStyleUrl() { SafeHtml html = SafeHtmls.fromStyleUrl( TrustedResourceUrls.fromConstant("https://example.com/&<\"'style.css")); assertEquals("<style type=\"text/css\" " + "src=\"https://example.com/&amp;&lt;&quot;&#39;style.css\"></style>", html.getSafeHtmlString()); } public void testToAndFromProto() { String html = "<b>Hello World</b>";
SafeHtml safeHtml = newSafeHtmlForTest(html);
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeStyleSheetsTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase;
// **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeStyleSheetsTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeStyleSheets}. */ @GwtCompatible public class SafeStyleSheetsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/SafeStyleSheetsTest.java import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; // **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeStyleSheetsTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeStyleSheets}. */ @GwtCompatible public class SafeStyleSheetsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
assertClassIsNotExportable(SafeStyleSheets.class);
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeStylesTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable;
// **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeStylesTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeStyles}. */ @GwtCompatible public class SafeStylesTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/SafeStylesTest.java import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; // **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeStylesTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeStyles}. */ @GwtCompatible public class SafeStylesTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
assertClassIsNotExportable(SafeStyles.class);
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeStyleBuilderTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.primitives.Chars; import com.google.errorprone.annotations.CompileTimeConstant; import junit.framework.TestCase;
// **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeStyleBuilderTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeStyleBuilder}. */ @GwtCompatible public class SafeStyleBuilderTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/SafeStyleBuilderTest.java import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import com.google.common.primitives.Chars; import com.google.errorprone.annotations.CompileTimeConstant; import junit.framework.TestCase; // **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeStyleBuilderTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeStyleBuilder}. */ @GwtCompatible public class SafeStyleBuilderTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
assertClassIsNotExportable(SafeStyleBuilder.class);
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeUrlTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeUrl newSafeUrlForTest(String string) { // return UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract(string); // }
import static com.google.common.html.types.testing.HtmlConversions.newSafeUrlForTest; import com.google.common.annotations.GwtCompatible; import com.google.common.testing.EqualsTester; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeUrl}. */ @GwtCompatible public class SafeUrlTest extends TestCase { // TODO(mlourenco): Remove usage newSafeUrlForTest once we have a GWT // version of builders. public void testToString_returnsDebugString() {
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeUrl newSafeUrlForTest(String string) { // return UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract(string); // } // Path: types/src/test/java/com/google/common/html/types/SafeUrlTest.java import static com.google.common.html.types.testing.HtmlConversions.newSafeUrlForTest; import com.google.common.annotations.GwtCompatible; import com.google.common.testing.EqualsTester; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeUrl}. */ @GwtCompatible public class SafeUrlTest extends TestCase { // TODO(mlourenco): Remove usage newSafeUrlForTest once we have a GWT // version of builders. public void testToString_returnsDebugString() {
assertEquals("SafeUrl{url}", newSafeUrlForTest("url").toString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeScriptsTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.nio.charset.Charset; import junit.framework.TestCase;
// **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeScriptsTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeScripts}. */ @GwtCompatible public class SafeScriptsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/SafeScriptsTest.java import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.nio.charset.Charset; import junit.framework.TestCase; // **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/SafeScriptsTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link SafeScripts}. */ @GwtCompatible public class SafeScriptsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
assertClassIsNotExportable(SafeScripts.class);
google/safe-html-types
types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // }
import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link LegacyConversions}. */ @GwtCompatible public class LegacyConversionsTest extends TestCase { public void testRiskilyAssumeSafeHtml() { String html = "<script>this is not valid SafeHtml"; assertEquals( html,
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // } // Path: types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link LegacyConversions}. */ @GwtCompatible public class LegacyConversionsTest extends TestCase { public void testRiskilyAssumeSafeHtml() { String html = "<script>this is not valid SafeHtml"; assertEquals( html,
riskilyAssumeSafeHtml(html).getSafeHtmlString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // }
import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link LegacyConversions}. */ @GwtCompatible public class LegacyConversionsTest extends TestCase { public void testRiskilyAssumeSafeHtml() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, riskilyAssumeSafeHtml(html).getSafeHtmlString()); } public void testRiskilyAssumeSafeScript() { String script = "invalid SafeScript"; assertEquals( script,
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // } // Path: types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link LegacyConversions}. */ @GwtCompatible public class LegacyConversionsTest extends TestCase { public void testRiskilyAssumeSafeHtml() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, riskilyAssumeSafeHtml(html).getSafeHtmlString()); } public void testRiskilyAssumeSafeScript() { String script = "invalid SafeScript"; assertEquals( script,
riskilyAssumeSafeScript(script).getSafeScriptString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // }
import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link LegacyConversions}. */ @GwtCompatible public class LegacyConversionsTest extends TestCase { public void testRiskilyAssumeSafeHtml() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, riskilyAssumeSafeHtml(html).getSafeHtmlString()); } public void testRiskilyAssumeSafeScript() { String script = "invalid SafeScript"; assertEquals( script, riskilyAssumeSafeScript(script).getSafeScriptString()); } public void testRiskilyAssumeSafeStyle() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style,
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // } // Path: types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link LegacyConversions}. */ @GwtCompatible public class LegacyConversionsTest extends TestCase { public void testRiskilyAssumeSafeHtml() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, riskilyAssumeSafeHtml(html).getSafeHtmlString()); } public void testRiskilyAssumeSafeScript() { String script = "invalid SafeScript"; assertEquals( script, riskilyAssumeSafeScript(script).getSafeScriptString()); } public void testRiskilyAssumeSafeStyle() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style,
riskilyAssumeSafeStyle(style).getSafeStyleString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // }
import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase;
/* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link LegacyConversions}. */ @GwtCompatible public class LegacyConversionsTest extends TestCase { public void testRiskilyAssumeSafeHtml() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, riskilyAssumeSafeHtml(html).getSafeHtmlString()); } public void testRiskilyAssumeSafeScript() { String script = "invalid SafeScript"; assertEquals( script, riskilyAssumeSafeScript(script).getSafeScriptString()); } public void testRiskilyAssumeSafeStyle() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, riskilyAssumeSafeStyle(style).getSafeStyleString()); } public void testRiskilyAssumeSafeStyleSheet() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet,
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // } // Path: types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link LegacyConversions}. */ @GwtCompatible public class LegacyConversionsTest extends TestCase { public void testRiskilyAssumeSafeHtml() { String html = "<script>this is not valid SafeHtml"; assertEquals( html, riskilyAssumeSafeHtml(html).getSafeHtmlString()); } public void testRiskilyAssumeSafeScript() { String script = "invalid SafeScript"; assertEquals( script, riskilyAssumeSafeScript(script).getSafeScriptString()); } public void testRiskilyAssumeSafeStyle() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, riskilyAssumeSafeStyle(style).getSafeStyleString()); } public void testRiskilyAssumeSafeStyleSheet() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet,
riskilyAssumeSafeStyleSheet(styleSheet).getSafeStyleSheetString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // }
import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase;
assertEquals( html, riskilyAssumeSafeHtml(html).getSafeHtmlString()); } public void testRiskilyAssumeSafeScript() { String script = "invalid SafeScript"; assertEquals( script, riskilyAssumeSafeScript(script).getSafeScriptString()); } public void testRiskilyAssumeSafeStyle() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, riskilyAssumeSafeStyle(style).getSafeStyleString()); } public void testRiskilyAssumeSafeStyleSheet() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet, riskilyAssumeSafeStyleSheet(styleSheet).getSafeStyleSheetString()); } public void testRiskilyAssumeSafeUrl() { String url = "data:this will not be sanitized"; assertEquals( url,
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // } // Path: types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; assertEquals( html, riskilyAssumeSafeHtml(html).getSafeHtmlString()); } public void testRiskilyAssumeSafeScript() { String script = "invalid SafeScript"; assertEquals( script, riskilyAssumeSafeScript(script).getSafeScriptString()); } public void testRiskilyAssumeSafeStyle() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, riskilyAssumeSafeStyle(style).getSafeStyleString()); } public void testRiskilyAssumeSafeStyleSheet() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet, riskilyAssumeSafeStyleSheet(styleSheet).getSafeStyleSheetString()); } public void testRiskilyAssumeSafeUrl() { String url = "data:this will not be sanitized"; assertEquals( url,
riskilyAssumeSafeUrl(url).getSafeUrlString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // }
import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase;
assertEquals( script, riskilyAssumeSafeScript(script).getSafeScriptString()); } public void testRiskilyAssumeSafeStyle() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, riskilyAssumeSafeStyle(style).getSafeStyleString()); } public void testRiskilyAssumeSafeStyleSheet() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet, riskilyAssumeSafeStyleSheet(styleSheet).getSafeStyleSheetString()); } public void testRiskilyAssumeSafeUrl() { String url = "data:this will not be sanitized"; assertEquals( url, riskilyAssumeSafeUrl(url).getSafeUrlString()); } public void testRiskilyAssumeTrustedResourceUrl() { String url = "data:this will not be sanitized"; assertEquals( url,
// Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeHtml riskilyAssumeSafeHtml(String html) { // return new SafeHtml(html); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeScript riskilyAssumeSafeScript(String script) { // return new SafeScript(script); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyle riskilyAssumeSafeStyle(String style) { // return new SafeStyle(style); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static SafeStyleSheet riskilyAssumeSafeStyleSheet(String stylesheet) { // return new SafeStyleSheet(stylesheet); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // */ public static SafeUrl riskilyAssumeSafeUrl(String url) { // return new SafeUrl(url); // } // // Path: types/src/main/java/com/google/common/html/types/LegacyConversions.java // public static TrustedResourceUrl riskilyAssumeTrustedResourceUrl(String url) { // return new TrustedResourceUrl(url); // } // Path: types/src/test/java/com/google/common/html/types/LegacyConversionsTest.java import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeHtml; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeScript; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyle; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeStyleSheet; import static com.google.common.html.types.LegacyConversions.riskilyAssumeSafeUrl; import static com.google.common.html.types.LegacyConversions.riskilyAssumeTrustedResourceUrl; import com.google.common.annotations.GwtCompatible; import junit.framework.TestCase; assertEquals( script, riskilyAssumeSafeScript(script).getSafeScriptString()); } public void testRiskilyAssumeSafeStyle() { String style = "width:expression(this is not valid SafeStyle"; assertEquals( style, riskilyAssumeSafeStyle(style).getSafeStyleString()); } public void testRiskilyAssumeSafeStyleSheet() { String styleSheet = "selector { not a valid SafeStyleSheet"; assertEquals( styleSheet, riskilyAssumeSafeStyleSheet(styleSheet).getSafeStyleSheetString()); } public void testRiskilyAssumeSafeUrl() { String url = "data:this will not be sanitized"; assertEquals( url, riskilyAssumeSafeUrl(url).getSafeUrlString()); } public void testRiskilyAssumeTrustedResourceUrl() { String url = "data:this will not be sanitized"; assertEquals( url,
riskilyAssumeTrustedResourceUrl(url).getTrustedResourceUrlString());
google/safe-html-types
types/src/test/java/com/google/common/html/types/TrustedResourceUrlsTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible;
// **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/TrustedResourceUrlsTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link TrustedResourceUrls}. */ @GwtCompatible(emulated = true) public class TrustedResourceUrlsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
// Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/TrustedResourceUrlsTest.java import com.google.common.annotations.GwtIncompatible; import junit.framework.TestCase; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; // **** GENERATED CODE, DO NOT MODIFY **** // This file was generated via preprocessing from input: // javatests/com/google/common/html/types/TrustedResourceUrlsTest.java.tpl // *************************************** /* * Copyright 2016 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.common.html.types; /** * Unit tests for {@link TrustedResourceUrls}. */ @GwtCompatible(emulated = true) public class TrustedResourceUrlsTest extends TestCase { @GwtIncompatible("Assertions.assertClassIsNotExportable") public void testClassNotExportable() {
assertClassIsNotExportable(TrustedResourceUrls.class);
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeHtmlBuilderTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeUrl newSafeUrlForTest(String string) { // return UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import static com.google.common.html.types.testing.HtmlConversions.newSafeUrlForTest; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.ArrayList; import junit.framework.TestCase;
fail("Data attribute shouldn't allow setting arbitrary attributes."); } catch (IllegalArgumentException expected) { } } public void testAllowsResourceUrlInLinkedStylesheet() { TrustedResourceUrl url = TrustedResourceUrls.fromConstant("a"); assertSameHtml( "<link rel=\"stylesheet\" href=\"a\">", new SafeHtmlBuilder("link").setRel("stylesheet").setHref(url)); assertSameHtml( "<link href=\"a\" rel=\"stylesheet\">", new SafeHtmlBuilder("link").setHref(url).setRel("stylesheet")); } public void testAllowsResourceUrlInLinkedDangerousContexts() { TrustedResourceUrl url = TrustedResourceUrls.fromConstant("a"); assertSameHtml( "<link rel=\"serviceworker\" href=\"a\">", new SafeHtmlBuilder("link").setRel("serviceworker").setHref(url)); assertSameHtml( "<link rel=\"import\" href=\"a\">", new SafeHtmlBuilder("link").setRel("next").setHref(url).setRel("import")); } public void testAllowsSafeUrlInLinkedIcon() { assertSameHtml("<link rel=\"icon\" href=\"a\">", new SafeHtmlBuilder("link") .setRel("icon")
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeUrl newSafeUrlForTest(String string) { // return UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/SafeHtmlBuilderTest.java import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import static com.google.common.html.types.testing.HtmlConversions.newSafeUrlForTest; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.ArrayList; import junit.framework.TestCase; fail("Data attribute shouldn't allow setting arbitrary attributes."); } catch (IllegalArgumentException expected) { } } public void testAllowsResourceUrlInLinkedStylesheet() { TrustedResourceUrl url = TrustedResourceUrls.fromConstant("a"); assertSameHtml( "<link rel=\"stylesheet\" href=\"a\">", new SafeHtmlBuilder("link").setRel("stylesheet").setHref(url)); assertSameHtml( "<link href=\"a\" rel=\"stylesheet\">", new SafeHtmlBuilder("link").setHref(url).setRel("stylesheet")); } public void testAllowsResourceUrlInLinkedDangerousContexts() { TrustedResourceUrl url = TrustedResourceUrls.fromConstant("a"); assertSameHtml( "<link rel=\"serviceworker\" href=\"a\">", new SafeHtmlBuilder("link").setRel("serviceworker").setHref(url)); assertSameHtml( "<link rel=\"import\" href=\"a\">", new SafeHtmlBuilder("link").setRel("next").setHref(url).setRel("import")); } public void testAllowsSafeUrlInLinkedIcon() { assertSameHtml("<link rel=\"icon\" href=\"a\">", new SafeHtmlBuilder("link") .setRel("icon")
.setHref(newSafeUrlForTest("a")));
google/safe-html-types
types/src/test/java/com/google/common/html/types/SafeHtmlBuilderTest.java
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeUrl newSafeUrlForTest(String string) { // return UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // }
import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import static com.google.common.html.types.testing.HtmlConversions.newSafeUrlForTest; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.ArrayList; import junit.framework.TestCase;
} catch (IllegalArgumentException expected) { } } public void testSettingAttributeAgainIsAllowed() { assertSameHtml( "<a title=\"c\"></a>", new SafeHtmlBuilder("a").setTitle("a").setTitle("c")); } public void testDisallowsUsingNullValues() { try { new SafeHtmlBuilder("a").setTitle(null); fail("The null attribute value shouldn't be allowed."); } catch (NullPointerException expected) { } } public void testDisallowsSafeUrlInIframeSrcAttribute() { try { new SafeHtmlBuilder("iframe").setSrc(newSafeUrlForTest("b")); fail("<iframe src> should require TrustedResourceUrl."); } catch (IllegalArgumentException expected) { } } public void testAllowsSafeHtmlInIframeSrcdocAttribute() { assertSameHtml( "<iframe srcdoc=\"&lt;a href=&quot;https://www.foo.com&quot;&gt;foo&lt;/a&gt;\"></iframe>", new SafeHtmlBuilder("iframe")
// Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeHtml newSafeHtmlForTest(String string) { // return UncheckedConversions.safeHtmlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/HtmlConversions.java // public static SafeUrl newSafeUrlForTest(String string) { // return UncheckedConversions.safeUrlFromStringKnownToSatisfyTypeContract(string); // } // // Path: types/src/main/java/com/google/common/html/types/testing/assertions/Assertions.java // public static void assertClassIsNotExportable(Class<?> klass) { // for (Class<?> annotation : EXPORTABLE_CLASS_ANNOTATIONS) { // if (klass.isAnnotationPresent(annotation.asSubclass(Annotation.class))) { // throw new AssertionError( // "Class should not have annotation " + annotation.getName() // + ", @CompileTimeConstant can be bypassed: " + klass); // } // } // } // Path: types/src/test/java/com/google/common/html/types/SafeHtmlBuilderTest.java import static com.google.common.html.types.testing.HtmlConversions.newSafeHtmlForTest; import static com.google.common.html.types.testing.HtmlConversions.newSafeUrlForTest; import static com.google.common.html.types.testing.assertions.Assertions.assertClassIsNotExportable; import com.google.common.annotations.GwtCompatible; import com.google.common.annotations.GwtIncompatible; import java.util.ArrayList; import junit.framework.TestCase; } catch (IllegalArgumentException expected) { } } public void testSettingAttributeAgainIsAllowed() { assertSameHtml( "<a title=\"c\"></a>", new SafeHtmlBuilder("a").setTitle("a").setTitle("c")); } public void testDisallowsUsingNullValues() { try { new SafeHtmlBuilder("a").setTitle(null); fail("The null attribute value shouldn't be allowed."); } catch (NullPointerException expected) { } } public void testDisallowsSafeUrlInIframeSrcAttribute() { try { new SafeHtmlBuilder("iframe").setSrc(newSafeUrlForTest("b")); fail("<iframe src> should require TrustedResourceUrl."); } catch (IllegalArgumentException expected) { } } public void testAllowsSafeHtmlInIframeSrcdocAttribute() { assertSameHtml( "<iframe srcdoc=\"&lt;a href=&quot;https://www.foo.com&quot;&gt;foo&lt;/a&gt;\"></iframe>", new SafeHtmlBuilder("iframe")
.setSrcdoc(newSafeHtmlForTest("<a href=\"https://www.foo.com\">foo</a>")));
google/safe-html-types
types/src/main/java/com/google/common/html/types/SafeHtmlBuilder.java
// Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String coerceToInterchangeValid(String text) { // // MOE elided code that uses a non-public library to make sure text only // // contains minimally-encoded Unicode scalar values that can appear in // // both HTML and XML. // return text; // // } // // Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String escapeHtmlInternal(String s) { // return HTML_ESCAPER.escape(s); // // }
import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import javax.annotation.CheckReturnValue; import javax.annotation.Generated; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; import static com.google.common.html.types.BuilderUtils.coerceToInterchangeValid; import static com.google.common.html.types.BuilderUtils.escapeHtmlInternal; import com.google.common.annotations.GwtCompatible; import com.google.errorprone.annotations.CompileTimeConstant; import java.util.ArrayList; import java.util.Collections;
&& relValue != null && !LINK_HREF_SAFE_URL_REL_WHITELIST.contains(relValue.toLowerCase(Locale.ENGLISH))) { throw new IllegalArgumentException( "SafeUrl values for the href attribute are not allowed on <link rel=" + relValue + ">. Did you intend to use a TrustedResourceUrl?"); } } private void checkNotVoidElement() { if (VOID_ELEMENTS.contains(elementName)) { throw new IllegalStateException( "Element \"" + elementName + "\" is a void element and so cannot have content."); } } /** * HTML-escapes and appends {@code text} to this element's content. * * @throws IllegalStateException if this builder represents a void element */ public SafeHtmlBuilder escapeAndAppendContent(String text) { // htmlEscape() unicode coerces in non-portable version. return appendContent(SafeHtmls.htmlEscape(text)); } @CheckReturnValue public SafeHtml build() { StringBuilder sb = new StringBuilder("<" + elementName); for (Map.Entry<String, String> entry : attributes.entrySet()) {
// Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String coerceToInterchangeValid(String text) { // // MOE elided code that uses a non-public library to make sure text only // // contains minimally-encoded Unicode scalar values that can appear in // // both HTML and XML. // return text; // // } // // Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String escapeHtmlInternal(String s) { // return HTML_ESCAPER.escape(s); // // } // Path: types/src/main/java/com/google/common/html/types/SafeHtmlBuilder.java import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import javax.annotation.CheckReturnValue; import javax.annotation.Generated; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; import static com.google.common.html.types.BuilderUtils.coerceToInterchangeValid; import static com.google.common.html.types.BuilderUtils.escapeHtmlInternal; import com.google.common.annotations.GwtCompatible; import com.google.errorprone.annotations.CompileTimeConstant; import java.util.ArrayList; import java.util.Collections; && relValue != null && !LINK_HREF_SAFE_URL_REL_WHITELIST.contains(relValue.toLowerCase(Locale.ENGLISH))) { throw new IllegalArgumentException( "SafeUrl values for the href attribute are not allowed on <link rel=" + relValue + ">. Did you intend to use a TrustedResourceUrl?"); } } private void checkNotVoidElement() { if (VOID_ELEMENTS.contains(elementName)) { throw new IllegalStateException( "Element \"" + elementName + "\" is a void element and so cannot have content."); } } /** * HTML-escapes and appends {@code text} to this element's content. * * @throws IllegalStateException if this builder represents a void element */ public SafeHtmlBuilder escapeAndAppendContent(String text) { // htmlEscape() unicode coerces in non-portable version. return appendContent(SafeHtmls.htmlEscape(text)); } @CheckReturnValue public SafeHtml build() { StringBuilder sb = new StringBuilder("<" + elementName); for (Map.Entry<String, String> entry : attributes.entrySet()) {
sb.append(" " + entry.getKey() + "=\"" + escapeHtmlInternal(entry.getValue()) + "\"");
google/safe-html-types
types/src/main/java/com/google/common/html/types/SafeHtmlBuilder.java
// Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String coerceToInterchangeValid(String text) { // // MOE elided code that uses a non-public library to make sure text only // // contains minimally-encoded Unicode scalar values that can appear in // // both HTML and XML. // return text; // // } // // Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String escapeHtmlInternal(String s) { // return HTML_ESCAPER.escape(s); // // }
import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import javax.annotation.CheckReturnValue; import javax.annotation.Generated; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; import static com.google.common.html.types.BuilderUtils.coerceToInterchangeValid; import static com.google.common.html.types.BuilderUtils.escapeHtmlInternal; import com.google.common.annotations.GwtCompatible; import com.google.errorprone.annotations.CompileTimeConstant; import java.util.ArrayList; import java.util.Collections;
public SafeHtml build() { StringBuilder sb = new StringBuilder("<" + elementName); for (Map.Entry<String, String> entry : attributes.entrySet()) { sb.append(" " + entry.getKey() + "=\"" + escapeHtmlInternal(entry.getValue()) + "\""); } boolean isVoid = VOID_ELEMENTS.contains(elementName); if (isVoid && useSlashOnVoid) { sb.append("/"); } sb.append(">"); if (!isVoid) { for (SafeHtml content : contents) { sb.append(content.getSafeHtmlString()); } sb.append("</" + elementName + ">"); } return SafeHtmls.create(sb.toString()); } private static final Set<String> createUnmodifiableSet(String... strings) { HashSet<String> set = new HashSet<>(); Collections.addAll(set, strings); return Collections.unmodifiableSet(set); } private SafeHtmlBuilder setAttribute(@CompileTimeConstant final String name, String value) { if (value == null) { throw new NullPointerException("setAttribute requires a non-null value."); }
// Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String coerceToInterchangeValid(String text) { // // MOE elided code that uses a non-public library to make sure text only // // contains minimally-encoded Unicode scalar values that can appear in // // both HTML and XML. // return text; // // } // // Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String escapeHtmlInternal(String s) { // return HTML_ESCAPER.escape(s); // // } // Path: types/src/main/java/com/google/common/html/types/SafeHtmlBuilder.java import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import javax.annotation.CheckReturnValue; import javax.annotation.Generated; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; import static com.google.common.html.types.BuilderUtils.coerceToInterchangeValid; import static com.google.common.html.types.BuilderUtils.escapeHtmlInternal; import com.google.common.annotations.GwtCompatible; import com.google.errorprone.annotations.CompileTimeConstant; import java.util.ArrayList; import java.util.Collections; public SafeHtml build() { StringBuilder sb = new StringBuilder("<" + elementName); for (Map.Entry<String, String> entry : attributes.entrySet()) { sb.append(" " + entry.getKey() + "=\"" + escapeHtmlInternal(entry.getValue()) + "\""); } boolean isVoid = VOID_ELEMENTS.contains(elementName); if (isVoid && useSlashOnVoid) { sb.append("/"); } sb.append(">"); if (!isVoid) { for (SafeHtml content : contents) { sb.append(content.getSafeHtmlString()); } sb.append("</" + elementName + ">"); } return SafeHtmls.create(sb.toString()); } private static final Set<String> createUnmodifiableSet(String... strings) { HashSet<String> set = new HashSet<>(); Collections.addAll(set, strings); return Collections.unmodifiableSet(set); } private SafeHtmlBuilder setAttribute(@CompileTimeConstant final String name, String value) { if (value == null) { throw new NullPointerException("setAttribute requires a non-null value."); }
attributes.put(name, coerceToInterchangeValid(value));
google/safe-html-types
examples/third_party_library/src/main/java/com/example/safehtmltypes/Example.java
// Path: types/src/main/java/com/google/common/html/types/SafeHtml.java // @CheckReturnValue // @Immutable // @JsType // public final class SafeHtml { // // /** The SafeHtml wrapping an empty string. */ // public static final SafeHtml EMPTY = new SafeHtml(""); // // private final String privateDoNotAccessOrElseSafeHtmlWrappedValue; // // SafeHtml(String html) { // if (html == null) { // throw new NullPointerException(); // } // this.privateDoNotAccessOrElseSafeHtmlWrappedValue = html; // } // // @Override // public int hashCode() { // return privateDoNotAccessOrElseSafeHtmlWrappedValue.hashCode() ^ 0x33b02fa9; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof SafeHtml)) { // return false; // } // SafeHtml that = (SafeHtml) other; // return this.privateDoNotAccessOrElseSafeHtmlWrappedValue.equals( // that.privateDoNotAccessOrElseSafeHtmlWrappedValue); // } // // /** // * Returns a debug representation of this value's underlying string, NOT the string representation // * of the SafeHtml. // * // * <p>Having {@code toString()} return a debug representation is intentional. This type has // * a GWT-compiled JavaScript version; JavaScript has no static typing and a distinct method // * method name provides a modicum of type-safety. // * // * @see #getSafeHtmlString // */ // @Override // public String toString() { // return "SafeHtml{" + privateDoNotAccessOrElseSafeHtmlWrappedValue + "}"; // } // // /** // * Returns this value's underlying string. See class documentation for what guarantees exist on // * the returned string. // */ // // NOTE(mlourenco): jslayout depends on this exact method name when generating code, be careful if // // changing it. // public String getSafeHtmlString() { // return privateDoNotAccessOrElseSafeHtmlWrappedValue; // } // }
import com.google.common.html.types.SafeHtml; import org.owasp.html.Sanitizers; import org.owasp.html.htmltypes.SafeHtmlMint;
package com.example.safehtmltypes; /** * Demonstrates that a third-party library can use UncheckedConversions */ public final class Example { public static void main(String[] argv) { SafeHtmlMint mint = SafeHtmlMint.fromPolicyFactory( Sanitizers.FORMATTING.and(Sanitizers.BLOCKS)); for (String arg : argv) {
// Path: types/src/main/java/com/google/common/html/types/SafeHtml.java // @CheckReturnValue // @Immutable // @JsType // public final class SafeHtml { // // /** The SafeHtml wrapping an empty string. */ // public static final SafeHtml EMPTY = new SafeHtml(""); // // private final String privateDoNotAccessOrElseSafeHtmlWrappedValue; // // SafeHtml(String html) { // if (html == null) { // throw new NullPointerException(); // } // this.privateDoNotAccessOrElseSafeHtmlWrappedValue = html; // } // // @Override // public int hashCode() { // return privateDoNotAccessOrElseSafeHtmlWrappedValue.hashCode() ^ 0x33b02fa9; // } // // @Override // public boolean equals(Object other) { // if (!(other instanceof SafeHtml)) { // return false; // } // SafeHtml that = (SafeHtml) other; // return this.privateDoNotAccessOrElseSafeHtmlWrappedValue.equals( // that.privateDoNotAccessOrElseSafeHtmlWrappedValue); // } // // /** // * Returns a debug representation of this value's underlying string, NOT the string representation // * of the SafeHtml. // * // * <p>Having {@code toString()} return a debug representation is intentional. This type has // * a GWT-compiled JavaScript version; JavaScript has no static typing and a distinct method // * method name provides a modicum of type-safety. // * // * @see #getSafeHtmlString // */ // @Override // public String toString() { // return "SafeHtml{" + privateDoNotAccessOrElseSafeHtmlWrappedValue + "}"; // } // // /** // * Returns this value's underlying string. See class documentation for what guarantees exist on // * the returned string. // */ // // NOTE(mlourenco): jslayout depends on this exact method name when generating code, be careful if // // changing it. // public String getSafeHtmlString() { // return privateDoNotAccessOrElseSafeHtmlWrappedValue; // } // } // Path: examples/third_party_library/src/main/java/com/example/safehtmltypes/Example.java import com.google.common.html.types.SafeHtml; import org.owasp.html.Sanitizers; import org.owasp.html.htmltypes.SafeHtmlMint; package com.example.safehtmltypes; /** * Demonstrates that a third-party library can use UncheckedConversions */ public final class Example { public static void main(String[] argv) { SafeHtmlMint mint = SafeHtmlMint.fromPolicyFactory( Sanitizers.FORMATTING.and(Sanitizers.BLOCKS)); for (String arg : argv) {
SafeHtml html = mint.sanitize(arg);
google/safe-html-types
types/src/main/java/com/google/common/html/types/SafeHtmls.java
// Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String coerceToInterchangeValid(String text) { // // MOE elided code that uses a non-public library to make sure text only // // contains minimally-encoded Unicode scalar values that can appear in // // both HTML and XML. // return text; // // } // // Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String escapeHtmlInternal(String s) { // return HTML_ESCAPER.escape(s); // // }
import static com.google.common.html.types.BuilderUtils.coerceToInterchangeValid; import static com.google.common.html.types.BuilderUtils.escapeHtmlInternal; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Preconditions; import java.util.Arrays; import javax.annotation.CheckReturnValue;
* Creates a new SafeHtml which contains, in order, the string representations of the given * {@code htmls}. */ public static SafeHtml concat(SafeHtml... htmls) { return concat(Arrays.asList(htmls)); } /** * Creates a new SafeHtml which contains, in order, the string representations of the given * {@code htmls}. */ public static SafeHtml concat(Iterable<SafeHtml> htmls) { int concatLength = 0; for (SafeHtml html : htmls) { concatLength += html.getSafeHtmlString().length(); } StringBuilder result = new StringBuilder(concatLength); for (SafeHtml html : htmls) { result.append(html.getSafeHtmlString()); } return create(result.toString()); } // Default visibility for use by SafeHtmlBuilder. static SafeHtml create(String html) { return new SafeHtml(html); } private static String htmlEscapeInternal(String text) {
// Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String coerceToInterchangeValid(String text) { // // MOE elided code that uses a non-public library to make sure text only // // contains minimally-encoded Unicode scalar values that can appear in // // both HTML and XML. // return text; // // } // // Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String escapeHtmlInternal(String s) { // return HTML_ESCAPER.escape(s); // // } // Path: types/src/main/java/com/google/common/html/types/SafeHtmls.java import static com.google.common.html.types.BuilderUtils.coerceToInterchangeValid; import static com.google.common.html.types.BuilderUtils.escapeHtmlInternal; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Preconditions; import java.util.Arrays; import javax.annotation.CheckReturnValue; * Creates a new SafeHtml which contains, in order, the string representations of the given * {@code htmls}. */ public static SafeHtml concat(SafeHtml... htmls) { return concat(Arrays.asList(htmls)); } /** * Creates a new SafeHtml which contains, in order, the string representations of the given * {@code htmls}. */ public static SafeHtml concat(Iterable<SafeHtml> htmls) { int concatLength = 0; for (SafeHtml html : htmls) { concatLength += html.getSafeHtmlString().length(); } StringBuilder result = new StringBuilder(concatLength); for (SafeHtml html : htmls) { result.append(html.getSafeHtmlString()); } return create(result.toString()); } // Default visibility for use by SafeHtmlBuilder. static SafeHtml create(String html) { return new SafeHtml(html); } private static String htmlEscapeInternal(String text) {
return escapeHtmlInternal(coerceToInterchangeValid(text));
google/safe-html-types
types/src/main/java/com/google/common/html/types/SafeHtmls.java
// Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String coerceToInterchangeValid(String text) { // // MOE elided code that uses a non-public library to make sure text only // // contains minimally-encoded Unicode scalar values that can appear in // // both HTML and XML. // return text; // // } // // Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String escapeHtmlInternal(String s) { // return HTML_ESCAPER.escape(s); // // }
import static com.google.common.html.types.BuilderUtils.coerceToInterchangeValid; import static com.google.common.html.types.BuilderUtils.escapeHtmlInternal; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Preconditions; import java.util.Arrays; import javax.annotation.CheckReturnValue;
* Creates a new SafeHtml which contains, in order, the string representations of the given * {@code htmls}. */ public static SafeHtml concat(SafeHtml... htmls) { return concat(Arrays.asList(htmls)); } /** * Creates a new SafeHtml which contains, in order, the string representations of the given * {@code htmls}. */ public static SafeHtml concat(Iterable<SafeHtml> htmls) { int concatLength = 0; for (SafeHtml html : htmls) { concatLength += html.getSafeHtmlString().length(); } StringBuilder result = new StringBuilder(concatLength); for (SafeHtml html : htmls) { result.append(html.getSafeHtmlString()); } return create(result.toString()); } // Default visibility for use by SafeHtmlBuilder. static SafeHtml create(String html) { return new SafeHtml(html); } private static String htmlEscapeInternal(String text) {
// Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String coerceToInterchangeValid(String text) { // // MOE elided code that uses a non-public library to make sure text only // // contains minimally-encoded Unicode scalar values that can appear in // // both HTML and XML. // return text; // // } // // Path: types/src/main/java/com/google/common/html/types/BuilderUtils.java // static String escapeHtmlInternal(String s) { // return HTML_ESCAPER.escape(s); // // } // Path: types/src/main/java/com/google/common/html/types/SafeHtmls.java import static com.google.common.html.types.BuilderUtils.coerceToInterchangeValid; import static com.google.common.html.types.BuilderUtils.escapeHtmlInternal; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Preconditions; import java.util.Arrays; import javax.annotation.CheckReturnValue; * Creates a new SafeHtml which contains, in order, the string representations of the given * {@code htmls}. */ public static SafeHtml concat(SafeHtml... htmls) { return concat(Arrays.asList(htmls)); } /** * Creates a new SafeHtml which contains, in order, the string representations of the given * {@code htmls}. */ public static SafeHtml concat(Iterable<SafeHtml> htmls) { int concatLength = 0; for (SafeHtml html : htmls) { concatLength += html.getSafeHtmlString().length(); } StringBuilder result = new StringBuilder(concatLength); for (SafeHtml html : htmls) { result.append(html.getSafeHtmlString()); } return create(result.toString()); } // Default visibility for use by SafeHtmlBuilder. static SafeHtml create(String html) { return new SafeHtml(html); } private static String htmlEscapeInternal(String text) {
return escapeHtmlInternal(coerceToInterchangeValid(text));
syvaidya/openstego
src/main/java/com/openstego/desktop/plugin/dwtkim/DWTKimErrors.java
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // }
import com.openstego.desktop.OpenStegoException;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.plugin.dwtkim; /** * Class to store error codes for DWT Kim plugin */ public class DWTKimErrors { /** * Error Code - No cover file given */ public static final int ERR_NO_COVER_FILE = 1; /** * Error Code - Image decomposition levels are not enough */ public static final int ERR_DECOMP_LEVEL_NOT_ENOUGH = 2; /** * Error Code - Invalid signature file provided */ public static final int ERR_SIG_NOT_VALID = 3; /** * Initialize the error code - message key map */ public static void init() {
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // } // Path: src/main/java/com/openstego/desktop/plugin/dwtkim/DWTKimErrors.java import com.openstego.desktop.OpenStegoException; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.plugin.dwtkim; /** * Class to store error codes for DWT Kim plugin */ public class DWTKimErrors { /** * Error Code - No cover file given */ public static final int ERR_NO_COVER_FILE = 1; /** * Error Code - Image decomposition levels are not enough */ public static final int ERR_DECOMP_LEVEL_NOT_ENOUGH = 2; /** * Error Code - Invalid signature file provided */ public static final int ERR_SIG_NOT_VALID = 3; /** * Initialize the error code - message key map */ public static void init() {
OpenStegoException.addErrorCode(DWTKimPlugin.NAMESPACE, ERR_NO_COVER_FILE, "err.cover.missing");
syvaidya/openstego
src/main/java/com/openstego/desktop/plugin/dwtdugad/DWTDugadErrors.java
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // }
import com.openstego.desktop.OpenStegoException;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.plugin.dwtdugad; /** * Class to store error codes for DWT Xie plugin */ public class DWTDugadErrors { /** * Error Code - No cover file given */ public static final int ERR_NO_COVER_FILE = 1; /** * Error Code - Invalid signature file provided */ public static final int ERR_SIG_NOT_VALID = 2; /** * Initialize the error code - message key map */ public static void init() {
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // } // Path: src/main/java/com/openstego/desktop/plugin/dwtdugad/DWTDugadErrors.java import com.openstego.desktop.OpenStegoException; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.plugin.dwtdugad; /** * Class to store error codes for DWT Xie plugin */ public class DWTDugadErrors { /** * Error Code - No cover file given */ public static final int ERR_NO_COVER_FILE = 1; /** * Error Code - Invalid signature file provided */ public static final int ERR_SIG_NOT_VALID = 2; /** * Initialize the error code - message key map */ public static void init() {
OpenStegoException.addErrorCode(DWTDugadPlugin.NAMESPACE, ERR_NO_COVER_FILE, "err.cover.missing");
syvaidya/openstego
src/main/java/com/openstego/desktop/OpenStegoException.java
// Path: src/main/java/com/openstego/desktop/util/LabelUtil.java // public class LabelUtil { // /** // * Static variable to hold the map of labels loaded from resource files // */ // private static final Map<String, ResourceBundle> map = new HashMap<>(); // // /** // * Static variable to store the namespace map // */ // private static final Map<String, LabelUtil> namespaceMap = new HashMap<>(); // // /** // * Method to add new namespace using resource bundle // * // * @param namespace Namespace for the labels // * @param bundle Resource bundle name // */ // public static void addNamespace(String namespace, String bundle) { // map.put(namespace, ResourceBundle.getBundle(bundle, Locale.getDefault())); // } // // /** // * Method to get instance of LabelUtil based on the namespace // * // * @param namespace Namespace for the labels // * @return Instance of LabelUtil // */ // public static LabelUtil getInstance(String namespace) { // LabelUtil util; // // util = namespaceMap.get(namespace); // if (util == null) { // util = new LabelUtil(namespace); // namespaceMap.put(namespace, util); // } // // return util; // } // // /** // * Variable to store the current namespace // */ // private final String namespace; // // /** // * Constructor is protected // * // * @param namespace Namespace for the label // */ // protected LabelUtil(String namespace) { // this.namespace = namespace; // } // // /** // * Method to get label value for the given label key // * // * @param key Key for the label // * @return Display value for the label // */ // public String getString(String key) { // return (map.get(this.namespace)).getString(key); // } // // /** // * Method to get label value for the given label key (using optional parameters) // * // * @param key Key for the label // * @param parameters Parameters to pass for a parameterized label // * @return Display value for the label // */ // public String getString(String key, Object... parameters) { // return MessageFormat.format(getString(key), parameters); // } // }
import com.openstego.desktop.util.LabelUtil; import java.util.HashMap; import java.util.Map;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop; /** * Custom exception class for OpenStego */ public class OpenStegoException extends Exception { private static final long serialVersionUID = 668241029491685413L; /** * Error Code - Unhandled exception */ static final int UNHANDLED_EXCEPTION = 0; /** * Map to store error code to message key mapping */ private static final Map<String, String> errMsgKeyMap = new HashMap<>(); /** * Error code for the exception */ private final int errorCode; /** * Namespace for the exception */ private final String namespace; /** * Constructor using default namespace for unhandled exceptions * * @param cause Original exception which caused this exception to be raised */ public OpenStegoException(Throwable cause) { this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); } /** * Default constructor * * @param cause Original exception which caused this exception to be raised * @param namespace Namespace of the error * @param errorCode Error code for the exception */ public OpenStegoException(Throwable cause, String namespace, int errorCode) { this(cause, namespace, errorCode, (Object[]) null); } /** * Constructor with a single parameter for the message * * @param cause Original exception which caused this exception to be raised * @param namespace Namespace of the error * @param errorCode Error code for the exception * @param param Parameter for exception message */ public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { this(cause, namespace, errorCode, new Object[]{param}); } /** * Constructor which takes object array for parameters for the message * * @param cause Original exception which caused this exception to be raised * @param namespace Namespace of the error * @param errorCode Error code for the exception * @param params Parameters for exception message */ public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString()
// Path: src/main/java/com/openstego/desktop/util/LabelUtil.java // public class LabelUtil { // /** // * Static variable to hold the map of labels loaded from resource files // */ // private static final Map<String, ResourceBundle> map = new HashMap<>(); // // /** // * Static variable to store the namespace map // */ // private static final Map<String, LabelUtil> namespaceMap = new HashMap<>(); // // /** // * Method to add new namespace using resource bundle // * // * @param namespace Namespace for the labels // * @param bundle Resource bundle name // */ // public static void addNamespace(String namespace, String bundle) { // map.put(namespace, ResourceBundle.getBundle(bundle, Locale.getDefault())); // } // // /** // * Method to get instance of LabelUtil based on the namespace // * // * @param namespace Namespace for the labels // * @return Instance of LabelUtil // */ // public static LabelUtil getInstance(String namespace) { // LabelUtil util; // // util = namespaceMap.get(namespace); // if (util == null) { // util = new LabelUtil(namespace); // namespaceMap.put(namespace, util); // } // // return util; // } // // /** // * Variable to store the current namespace // */ // private final String namespace; // // /** // * Constructor is protected // * // * @param namespace Namespace for the label // */ // protected LabelUtil(String namespace) { // this.namespace = namespace; // } // // /** // * Method to get label value for the given label key // * // * @param key Key for the label // * @return Display value for the label // */ // public String getString(String key) { // return (map.get(this.namespace)).getString(key); // } // // /** // * Method to get label value for the given label key (using optional parameters) // * // * @param key Key for the label // * @param parameters Parameters to pass for a parameterized label // * @return Display value for the label // */ // public String getString(String key, Object... parameters) { // return MessageFormat.format(getString(key), parameters); // } // } // Path: src/main/java/com/openstego/desktop/OpenStegoException.java import com.openstego.desktop.util.LabelUtil; import java.util.HashMap; import java.util.Map; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop; /** * Custom exception class for OpenStego */ public class OpenStegoException extends Exception { private static final long serialVersionUID = 668241029491685413L; /** * Error Code - Unhandled exception */ static final int UNHANDLED_EXCEPTION = 0; /** * Map to store error code to message key mapping */ private static final Map<String, String> errMsgKeyMap = new HashMap<>(); /** * Error code for the exception */ private final int errorCode; /** * Namespace for the exception */ private final String namespace; /** * Constructor using default namespace for unhandled exceptions * * @param cause Original exception which caused this exception to be raised */ public OpenStegoException(Throwable cause) { this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); } /** * Default constructor * * @param cause Original exception which caused this exception to be raised * @param namespace Namespace of the error * @param errorCode Error code for the exception */ public OpenStegoException(Throwable cause, String namespace, int errorCode) { this(cause, namespace, errorCode, (Object[]) null); } /** * Constructor with a single parameter for the message * * @param cause Original exception which caused this exception to be raised * @param namespace Namespace of the error * @param errorCode Error code for the exception * @param param Parameter for exception message */ public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { this(cause, namespace, errorCode, new Object[]{param}); } /** * Constructor which takes object array for parameters for the message * * @param cause Original exception which caused this exception to be raised * @param namespace Namespace of the error * @param errorCode Error code for the exception * @param params Parameters for exception message */ public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString()
: LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause);
syvaidya/openstego
src/main/java/com/openstego/desktop/plugin/template/dct/DCTErrors.java
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // }
import com.openstego.desktop.OpenStegoException;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.plugin.template.dct; /** * Class to store error codes for DCT plugin template */ public class DCTErrors { /** * Error Code - Invalid stego header data */ public static final int INVALID_STEGO_HEADER = 1; /** * Error Code - Invalid image header version */ public static final int INVALID_HEADER_VERSION = 2; /** * Initialize the error code - message key map */ public static void init() {
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // } // Path: src/main/java/com/openstego/desktop/plugin/template/dct/DCTErrors.java import com.openstego.desktop.OpenStegoException; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.plugin.template.dct; /** * Class to store error codes for DCT plugin template */ public class DCTErrors { /** * Error Code - Invalid stego header data */ public static final int INVALID_STEGO_HEADER = 1; /** * Error Code - Invalid image header version */ public static final int INVALID_HEADER_VERSION = 2; /** * Initialize the error code - message key map */ public static void init() {
OpenStegoException.addErrorCode(DCTPluginTemplate.NAMESPACE, INVALID_STEGO_HEADER, "err.invalidHeaderStamp");
syvaidya/openstego
src/main/java/com/openstego/desktop/util/cmd/CmdLineOptions.java
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // }
import com.openstego.desktop.OpenStegoException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.util.cmd; /** * Class to store the list of command line options * * @see CmdLineParser */ public class CmdLineOptions { /** * Map to store the standard command-line options */ private final Map<String, CmdLineOption> map = new HashMap<>(); /** * List to store the standard command-line options */ private final List<CmdLineOption> list = new ArrayList<>(); /** * Default constructor */ public CmdLineOptions() { } /** * Method to add the command-line option * * @param option Command-line option */ public void add(CmdLineOption option) { this.map.put(option.getName(), option); this.list.add(option); // Put reference by alternate name too if (option.getAltName() != null) { this.map.put(option.getAltName(), option); } } /** * Overloaded method to add the command-line option * * @param name Name of the option * @param altName Alternate name of the option * @param type Type of the option * @param takesArg Flag to indicate whether the option takes argument or not */ public void add(String name, String altName, int type, boolean takesArg) { add(new CmdLineOption(name, altName, type, takesArg)); } /** * Method to get the standard option data by name * * @param name Name of the option * @return Command-line option */ public CmdLineOption getOption(String name) { return this.map.get(name); } /** * Method to get the standard option data by index * * @param index Index of the option * @return Command-line option */ public CmdLineOption getOption(int index) { return this.list.get(index); } /** * Method to get the value of the given option as String * * @param name Name of the option * @return Value of the command-line option */ public String getStringValue(String name) { CmdLineOption option = getOption(name); return (option == null) ? null : option.getValue().trim(); } /** * Method to get the value of the given option as integer * * @param name Name of the option * @param errNamespace Namespace to be used for exception in case of parsing error * @param errCode Error code to be used for exception in case of parsing error * @return null if options is not present on command line, else integer value * @throws OpenStegoException If value is provided but not an integer */
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // } // Path: src/main/java/com/openstego/desktop/util/cmd/CmdLineOptions.java import com.openstego.desktop.OpenStegoException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.util.cmd; /** * Class to store the list of command line options * * @see CmdLineParser */ public class CmdLineOptions { /** * Map to store the standard command-line options */ private final Map<String, CmdLineOption> map = new HashMap<>(); /** * List to store the standard command-line options */ private final List<CmdLineOption> list = new ArrayList<>(); /** * Default constructor */ public CmdLineOptions() { } /** * Method to add the command-line option * * @param option Command-line option */ public void add(CmdLineOption option) { this.map.put(option.getName(), option); this.list.add(option); // Put reference by alternate name too if (option.getAltName() != null) { this.map.put(option.getAltName(), option); } } /** * Overloaded method to add the command-line option * * @param name Name of the option * @param altName Alternate name of the option * @param type Type of the option * @param takesArg Flag to indicate whether the option takes argument or not */ public void add(String name, String altName, int type, boolean takesArg) { add(new CmdLineOption(name, altName, type, takesArg)); } /** * Method to get the standard option data by name * * @param name Name of the option * @return Command-line option */ public CmdLineOption getOption(String name) { return this.map.get(name); } /** * Method to get the standard option data by index * * @param index Index of the option * @return Command-line option */ public CmdLineOption getOption(int index) { return this.list.get(index); } /** * Method to get the value of the given option as String * * @param name Name of the option * @return Value of the command-line option */ public String getStringValue(String name) { CmdLineOption option = getOption(name); return (option == null) ? null : option.getValue().trim(); } /** * Method to get the value of the given option as integer * * @param name Name of the option * @param errNamespace Namespace to be used for exception in case of parsing error * @param errCode Error code to be used for exception in case of parsing error * @return null if options is not present on command line, else integer value * @throws OpenStegoException If value is provided but not an integer */
public Integer getIntegerValue(String name, String errNamespace, int errCode) throws OpenStegoException {
syvaidya/openstego
src/main/java/com/openstego/desktop/util/CommonUtil.java
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // }
import com.openstego.desktop.OpenStegoException; import javax.swing.*; import java.awt.*; import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.util; /** * Common utilities for OpenStego */ public class CommonUtil { /** * Constructor is private so that this class is not instantiated */ private CommonUtil() { } /** * Method to get byte array data from given InputStream * * @param is InputStream to read * @return Stream data as byte array * @throws OpenStegoException Processing issues */
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // } // Path: src/main/java/com/openstego/desktop/util/CommonUtil.java import com.openstego.desktop.OpenStegoException; import javax.swing.*; import java.awt.*; import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.util; /** * Common utilities for OpenStego */ public class CommonUtil { /** * Constructor is private so that this class is not instantiated */ private CommonUtil() { } /** * Method to get byte array data from given InputStream * * @param is InputStream to read * @return Stream data as byte array * @throws OpenStegoException Processing issues */
public static byte[] streamToBytes(InputStream is) throws OpenStegoException {
syvaidya/openstego
src/main/java/com/openstego/desktop/OpenStegoErrors.java
// Path: src/main/java/com/openstego/desktop/OpenStego.java // public static final String NAMESPACE = "OpenStego"; // // Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // }
import static com.openstego.desktop.OpenStego.NAMESPACE; import static com.openstego.desktop.OpenStegoException.addErrorCode;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop; /** * Custom exception class for OpenStego */ public class OpenStegoErrors { /** * Error Code - Invalid password */ public static final int INVALID_PASSWORD = 1; /** * Error Code - Invalid value for useCompression */ public static final int INVALID_USE_COMPR_VALUE = 2; /** * Error Code - Invalid value for useEncryption */ public static final int INVALID_USE_ENCRYPT_VALUE = 3; /** * Error Code - Invalid key name */ public static final int INVALID_KEY_NAME = 4; /** * Error Code - Corrupt Data */ public static final int CORRUPT_DATA = 5; /** * Error Code - No valid plugin */ public static final int NO_VALID_PLUGIN = 6; /** * Error Code - Image type invalid */ public static final int IMAGE_TYPE_INVALID = 7; /** * Error Code - Image file invalid */ public static final int IMAGE_FILE_INVALID = 8; /** * Error Code - No plugin specified */ public static final int NO_PLUGIN_SPECIFIED = 9; /** * Error Code - Plugin does not support watermarking */ public static final int PLUGIN_DOES_NOT_SUPPORT_WM = 10; /** * Error Code - Plugin not found */ public static final int PLUGIN_NOT_FOUND = 11; /** * Error Code - Image sizes mismatch */ public static final int IMAGE_SIZE_MISMATCH = 12; /** * Error Code - Plugin does not support data hiding */ public static final int PLUGIN_DOES_NOT_SUPPORT_DH = 14; /** * Error Code - Password is mandatory for 'gensig' operation */ public static final int PWD_MANDATORY_FOR_GENSIG = 15; /** * Error Code - Invalid key name */ public static final int INVALID_CRYPT_ALGO = 16; /** * Error Code - Invalid integer in user preference file */ public static final int USERPREF_INVALID_INT = 17; /** * Error Code - Invalid float in user preference file */ public static final int USERPREF_INVALID_FLOAT = 18; /** * Error Code - Invalid boolean in user preference file */ public static final int USERPREF_INVALID_BOOL = 19; /** * Initialize the error code - message key map */ public static void init() {
// Path: src/main/java/com/openstego/desktop/OpenStego.java // public static final String NAMESPACE = "OpenStego"; // // Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // Path: src/main/java/com/openstego/desktop/OpenStegoErrors.java import static com.openstego.desktop.OpenStego.NAMESPACE; import static com.openstego.desktop.OpenStegoException.addErrorCode; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop; /** * Custom exception class for OpenStego */ public class OpenStegoErrors { /** * Error Code - Invalid password */ public static final int INVALID_PASSWORD = 1; /** * Error Code - Invalid value for useCompression */ public static final int INVALID_USE_COMPR_VALUE = 2; /** * Error Code - Invalid value for useEncryption */ public static final int INVALID_USE_ENCRYPT_VALUE = 3; /** * Error Code - Invalid key name */ public static final int INVALID_KEY_NAME = 4; /** * Error Code - Corrupt Data */ public static final int CORRUPT_DATA = 5; /** * Error Code - No valid plugin */ public static final int NO_VALID_PLUGIN = 6; /** * Error Code - Image type invalid */ public static final int IMAGE_TYPE_INVALID = 7; /** * Error Code - Image file invalid */ public static final int IMAGE_FILE_INVALID = 8; /** * Error Code - No plugin specified */ public static final int NO_PLUGIN_SPECIFIED = 9; /** * Error Code - Plugin does not support watermarking */ public static final int PLUGIN_DOES_NOT_SUPPORT_WM = 10; /** * Error Code - Plugin not found */ public static final int PLUGIN_NOT_FOUND = 11; /** * Error Code - Image sizes mismatch */ public static final int IMAGE_SIZE_MISMATCH = 12; /** * Error Code - Plugin does not support data hiding */ public static final int PLUGIN_DOES_NOT_SUPPORT_DH = 14; /** * Error Code - Password is mandatory for 'gensig' operation */ public static final int PWD_MANDATORY_FOR_GENSIG = 15; /** * Error Code - Invalid key name */ public static final int INVALID_CRYPT_ALGO = 16; /** * Error Code - Invalid integer in user preference file */ public static final int USERPREF_INVALID_INT = 17; /** * Error Code - Invalid float in user preference file */ public static final int USERPREF_INVALID_FLOAT = 18; /** * Error Code - Invalid boolean in user preference file */ public static final int USERPREF_INVALID_BOOL = 19; /** * Initialize the error code - message key map */ public static void init() {
addErrorCode(NAMESPACE, INVALID_PASSWORD, "err.config.password.invalid");
syvaidya/openstego
src/main/java/com/openstego/desktop/OpenStegoErrors.java
// Path: src/main/java/com/openstego/desktop/OpenStego.java // public static final String NAMESPACE = "OpenStego"; // // Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // }
import static com.openstego.desktop.OpenStego.NAMESPACE; import static com.openstego.desktop.OpenStegoException.addErrorCode;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop; /** * Custom exception class for OpenStego */ public class OpenStegoErrors { /** * Error Code - Invalid password */ public static final int INVALID_PASSWORD = 1; /** * Error Code - Invalid value for useCompression */ public static final int INVALID_USE_COMPR_VALUE = 2; /** * Error Code - Invalid value for useEncryption */ public static final int INVALID_USE_ENCRYPT_VALUE = 3; /** * Error Code - Invalid key name */ public static final int INVALID_KEY_NAME = 4; /** * Error Code - Corrupt Data */ public static final int CORRUPT_DATA = 5; /** * Error Code - No valid plugin */ public static final int NO_VALID_PLUGIN = 6; /** * Error Code - Image type invalid */ public static final int IMAGE_TYPE_INVALID = 7; /** * Error Code - Image file invalid */ public static final int IMAGE_FILE_INVALID = 8; /** * Error Code - No plugin specified */ public static final int NO_PLUGIN_SPECIFIED = 9; /** * Error Code - Plugin does not support watermarking */ public static final int PLUGIN_DOES_NOT_SUPPORT_WM = 10; /** * Error Code - Plugin not found */ public static final int PLUGIN_NOT_FOUND = 11; /** * Error Code - Image sizes mismatch */ public static final int IMAGE_SIZE_MISMATCH = 12; /** * Error Code - Plugin does not support data hiding */ public static final int PLUGIN_DOES_NOT_SUPPORT_DH = 14; /** * Error Code - Password is mandatory for 'gensig' operation */ public static final int PWD_MANDATORY_FOR_GENSIG = 15; /** * Error Code - Invalid key name */ public static final int INVALID_CRYPT_ALGO = 16; /** * Error Code - Invalid integer in user preference file */ public static final int USERPREF_INVALID_INT = 17; /** * Error Code - Invalid float in user preference file */ public static final int USERPREF_INVALID_FLOAT = 18; /** * Error Code - Invalid boolean in user preference file */ public static final int USERPREF_INVALID_BOOL = 19; /** * Initialize the error code - message key map */ public static void init() {
// Path: src/main/java/com/openstego/desktop/OpenStego.java // public static final String NAMESPACE = "OpenStego"; // // Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // Path: src/main/java/com/openstego/desktop/OpenStegoErrors.java import static com.openstego.desktop.OpenStego.NAMESPACE; import static com.openstego.desktop.OpenStegoException.addErrorCode; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop; /** * Custom exception class for OpenStego */ public class OpenStegoErrors { /** * Error Code - Invalid password */ public static final int INVALID_PASSWORD = 1; /** * Error Code - Invalid value for useCompression */ public static final int INVALID_USE_COMPR_VALUE = 2; /** * Error Code - Invalid value for useEncryption */ public static final int INVALID_USE_ENCRYPT_VALUE = 3; /** * Error Code - Invalid key name */ public static final int INVALID_KEY_NAME = 4; /** * Error Code - Corrupt Data */ public static final int CORRUPT_DATA = 5; /** * Error Code - No valid plugin */ public static final int NO_VALID_PLUGIN = 6; /** * Error Code - Image type invalid */ public static final int IMAGE_TYPE_INVALID = 7; /** * Error Code - Image file invalid */ public static final int IMAGE_FILE_INVALID = 8; /** * Error Code - No plugin specified */ public static final int NO_PLUGIN_SPECIFIED = 9; /** * Error Code - Plugin does not support watermarking */ public static final int PLUGIN_DOES_NOT_SUPPORT_WM = 10; /** * Error Code - Plugin not found */ public static final int PLUGIN_NOT_FOUND = 11; /** * Error Code - Image sizes mismatch */ public static final int IMAGE_SIZE_MISMATCH = 12; /** * Error Code - Plugin does not support data hiding */ public static final int PLUGIN_DOES_NOT_SUPPORT_DH = 14; /** * Error Code - Password is mandatory for 'gensig' operation */ public static final int PWD_MANDATORY_FOR_GENSIG = 15; /** * Error Code - Invalid key name */ public static final int INVALID_CRYPT_ALGO = 16; /** * Error Code - Invalid integer in user preference file */ public static final int USERPREF_INVALID_INT = 17; /** * Error Code - Invalid float in user preference file */ public static final int USERPREF_INVALID_FLOAT = 18; /** * Error Code - Invalid boolean in user preference file */ public static final int USERPREF_INVALID_BOOL = 19; /** * Initialize the error code - message key map */ public static void init() {
addErrorCode(NAMESPACE, INVALID_PASSWORD, "err.config.password.invalid");
syvaidya/openstego
src/main/java/com/openstego/desktop/plugin/lsb/LSBErrors.java
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // }
import com.openstego.desktop.OpenStegoException;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.plugin.lsb; /** * Class to store error codes for LSB plugin */ public class LSBErrors { /** * Error Code - Error while reading image data */ public static final int ERR_IMAGE_DATA_READ = 1; /** * Error Code - Null value provided for image */ public static final int NULL_IMAGE_ARGUMENT = 2; /** * Error Code - Image size insufficient for data */ public static final int IMAGE_SIZE_INSUFFICIENT = 3; /** * Error Code - maxBitsUsedPerChannel is not a number */ public static final int MAX_BITS_NOT_NUMBER = 4; /** * Error Code - maxBitsUsedPerChannel is not in valid range */ public static final int MAX_BITS_NOT_IN_RANGE = 5; /** * Error Code - Invalid stego header data */ public static final int INVALID_STEGO_HEADER = 6; /** * Error Code - Invalid image header version */ public static final int INVALID_HEADER_VERSION = 7; /** * Initialize the error code - message key map */ public static void init() {
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // } // Path: src/main/java/com/openstego/desktop/plugin/lsb/LSBErrors.java import com.openstego.desktop.OpenStegoException; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.plugin.lsb; /** * Class to store error codes for LSB plugin */ public class LSBErrors { /** * Error Code - Error while reading image data */ public static final int ERR_IMAGE_DATA_READ = 1; /** * Error Code - Null value provided for image */ public static final int NULL_IMAGE_ARGUMENT = 2; /** * Error Code - Image size insufficient for data */ public static final int IMAGE_SIZE_INSUFFICIENT = 3; /** * Error Code - maxBitsUsedPerChannel is not a number */ public static final int MAX_BITS_NOT_NUMBER = 4; /** * Error Code - maxBitsUsedPerChannel is not in valid range */ public static final int MAX_BITS_NOT_IN_RANGE = 5; /** * Error Code - Invalid stego header data */ public static final int INVALID_STEGO_HEADER = 6; /** * Error Code - Invalid image header version */ public static final int INVALID_HEADER_VERSION = 7; /** * Initialize the error code - message key map */ public static void init() {
OpenStegoException.addErrorCode(LSBPlugin.NAMESPACE, ERR_IMAGE_DATA_READ, "err.image.read");
syvaidya/openstego
src/main/java/com/openstego/desktop/util/StringUtil.java
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // }
import com.openstego.desktop.OpenStegoException; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List;
/* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.util; /** * Utility class to manipulate strings */ public class StringUtil { /** * Constructor is private so that this class is not instantiated */ private StringUtil() { } /** * Method to convert byte array to hexadecimal string * * @param raw Raw byte array * @return Hex string */ public static String getHexString(byte[] raw) { BigInteger bigInteger = new BigInteger(1, raw); return String.format("%0" + (raw.length << 1) + "x", bigInteger); } /** * Method to get the long hash from the password. This is used for seeding the random number generator * * @param password Password to hash * @return Long hash of the password */
// Path: src/main/java/com/openstego/desktop/OpenStegoException.java // public class OpenStegoException extends Exception { // private static final long serialVersionUID = 668241029491685413L; // // /** // * Error Code - Unhandled exception // */ // static final int UNHANDLED_EXCEPTION = 0; // // /** // * Map to store error code to message key mapping // */ // private static final Map<String, String> errMsgKeyMap = new HashMap<>(); // // /** // * Error code for the exception // */ // private final int errorCode; // // /** // * Namespace for the exception // */ // private final String namespace; // // /** // * Constructor using default namespace for unhandled exceptions // * // * @param cause Original exception which caused this exception to be raised // */ // public OpenStegoException(Throwable cause) { // this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null); // } // // /** // * Default constructor // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode) { // this(cause, namespace, errorCode, (Object[]) null); // } // // /** // * Constructor with a single parameter for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param param Parameter for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) { // this(cause, namespace, errorCode, new Object[]{param}); // } // // /** // * Constructor which takes object array for parameters for the message // * // * @param cause Original exception which caused this exception to be raised // * @param namespace Namespace of the error // * @param errorCode Error code for the exception // * @param params Parameters for exception message // */ // public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) { // super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString() // : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause); // // this.namespace = namespace; // this.errorCode = errorCode; // } // // /** // * Get method for errorCode // * // * @return errorCode // */ // public int getErrorCode() { // return this.errorCode; // } // // /** // * Get method for namespace // * // * @return namespace // */ // public String getNamespace() { // return this.namespace; // } // // /** // * Method to add new error codes to the namespace // * // * @param namespace Namespace for the error // * @param errorCode Error code of the error // * @param labelKey Key of the label for the error // */ // public static void addErrorCode(String namespace, int errorCode, String labelKey) { // errMsgKeyMap.put(namespace + errorCode, labelKey); // } // } // Path: src/main/java/com/openstego/desktop/util/StringUtil.java import com.openstego.desktop.OpenStegoException; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; /* * Steganography utility to hide messages into cover files * Author: Samir Vaidya (mailto:syvaidya@gmail.com) * Copyright (c) Samir Vaidya */ package com.openstego.desktop.util; /** * Utility class to manipulate strings */ public class StringUtil { /** * Constructor is private so that this class is not instantiated */ private StringUtil() { } /** * Method to convert byte array to hexadecimal string * * @param raw Raw byte array * @return Hex string */ public static String getHexString(byte[] raw) { BigInteger bigInteger = new BigInteger(1, raw); return String.format("%0" + (raw.length << 1) + "x", bigInteger); } /** * Method to get the long hash from the password. This is used for seeding the random number generator * * @param password Password to hash * @return Long hash of the password */
public static long passwordHash(String password) throws OpenStegoException {