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 |
|---|---|---|---|---|---|---|
paolodongilli/SASAbus | src/it/sasabz/android/sasabus/classes/FavoritenList.java | // Path: src/it/sasabz/android/sasabus/SASAbus.java
// public class SASAbus extends Application {
// private int dbDownloadAttempts;
//
// private static Context context = null;
//
// @Override
// public void onCreate()
// {
// // Init values which could be loaded from files stored in res/raw
// setDbDownloadAttempts(0);
// super.onCreate();
// context = this.getApplicationContext();
// }
//
// @Override
// public void onTerminate()
// {
// //do nothing
// MySQLiteDBAdapter.closeAll();
// }
//
// /**
// * @return the Strings and Variables stored in the Context;
// */
// public static Context getContext()
// {
// return context;
// }
//
// /**
// * @param dbDownloadAttempts the dbDownloadAttempts to set
// */
// public void setDbDownloadAttempts(int dbDownloadAttempts) {
// this.dbDownloadAttempts = dbDownloadAttempts;
// }
//
// /**
// * @return the dbDownloadAttempts
// */
// public int getDbDownloadAttempts() {
// return dbDownloadAttempts;
// }
//
//
// }
| import it.sasabz.android.sasabus.SASAbus;
import java.util.Vector;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
| /**
*
* FavoritenList.java
*
*
* Copyright (C) 2012 Markus Windegger
*
* This file is part of SasaBus.
* SasaBus 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.
*
* SasaBus 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 SasaBus. If not, see <http://www.gnu.org/licenses/>.
*
*/
package it.sasabz.android.sasabus.classes;
public class FavoritenList {
/**
* This function returns a vector of all the objects momentanly avaiable in the database
* @return a vector of objects if all goes right, alternativ it returns a MyError
*/
public static Vector <Favorit>getList()
{
| // Path: src/it/sasabz/android/sasabus/SASAbus.java
// public class SASAbus extends Application {
// private int dbDownloadAttempts;
//
// private static Context context = null;
//
// @Override
// public void onCreate()
// {
// // Init values which could be loaded from files stored in res/raw
// setDbDownloadAttempts(0);
// super.onCreate();
// context = this.getApplicationContext();
// }
//
// @Override
// public void onTerminate()
// {
// //do nothing
// MySQLiteDBAdapter.closeAll();
// }
//
// /**
// * @return the Strings and Variables stored in the Context;
// */
// public static Context getContext()
// {
// return context;
// }
//
// /**
// * @param dbDownloadAttempts the dbDownloadAttempts to set
// */
// public void setDbDownloadAttempts(int dbDownloadAttempts) {
// this.dbDownloadAttempts = dbDownloadAttempts;
// }
//
// /**
// * @return the dbDownloadAttempts
// */
// public int getDbDownloadAttempts() {
// return dbDownloadAttempts;
// }
//
//
// }
// Path: src/it/sasabz/android/sasabus/classes/FavoritenList.java
import it.sasabz.android.sasabus.SASAbus;
import java.util.Vector;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
/**
*
* FavoritenList.java
*
*
* Copyright (C) 2012 Markus Windegger
*
* This file is part of SasaBus.
* SasaBus 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.
*
* SasaBus 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 SasaBus. If not, see <http://www.gnu.org/licenses/>.
*
*/
package it.sasabz.android.sasabus.classes;
public class FavoritenList {
/**
* This function returns a vector of all the objects momentanly avaiable in the database
* @return a vector of objects if all goes right, alternativ it returns a MyError
*/
public static Vector <Favorit>getList()
{
| SQLiteDatabase sqlite = new FavoritenDB(SASAbus.getContext()).getReadableDatabase();
|
paolodongilli/SASAbus | src/it/sasabz/android/sasabus/classes/adapter/MyAutocompleteAdapter.java | // Path: src/it/sasabz/android/sasabus/classes/dbobjects/DBObject.java
// public class DBObject {
//
// /*
// * The id is the integer which identifies the object in the database
// */
// private int id = 0;
//
// /**
// * This constructor creates an dbobject
// */
// public DBObject()
// {
// super();
// //Nothing to do
// }
//
// /**
// * this creates a dbobject with an identifier, which is the id
// * provided in the database
// * @param identifier is the identifier from the database
// */
// public DBObject(int identifier)
// {
// super();
// setId(identifier);
// }
//
// /**
// *
// * @return the integer which identifies the object in the database
// */
// public int getId() {
// return id;
// }
//
// /**
// *
// * @param id is the integer which identifies the object in the database
// */
// public void setId(int id) {
// this.id = id;
// }
//
//
//
// }
| import android.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import it.sasabz.android.sasabus.classes.dbobjects.DBObject;
import java.util.Iterator;
import java.util.Vector; | /**
*
* MyListAdapter.java
*
*
* Copyright (C) 2012 Markus Windegger
*
* This file is part of SasaBus.
* SasaBus 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.
*
* SasaBus 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 SasaBus. If not, see <http://www.gnu.org/licenses/>.
*
*/
package it.sasabz.android.sasabus.classes.adapter;
/**
* @author Markus Windegger (markus@mowiso.com)
*
*/
public class MyAutocompleteAdapter extends BaseAdapter implements Filterable{
private final Context context; | // Path: src/it/sasabz/android/sasabus/classes/dbobjects/DBObject.java
// public class DBObject {
//
// /*
// * The id is the integer which identifies the object in the database
// */
// private int id = 0;
//
// /**
// * This constructor creates an dbobject
// */
// public DBObject()
// {
// super();
// //Nothing to do
// }
//
// /**
// * this creates a dbobject with an identifier, which is the id
// * provided in the database
// * @param identifier is the identifier from the database
// */
// public DBObject(int identifier)
// {
// super();
// setId(identifier);
// }
//
// /**
// *
// * @return the integer which identifies the object in the database
// */
// public int getId() {
// return id;
// }
//
// /**
// *
// * @param id is the integer which identifies the object in the database
// */
// public void setId(int id) {
// this.id = id;
// }
//
//
//
// }
// Path: src/it/sasabz/android/sasabus/classes/adapter/MyAutocompleteAdapter.java
import android.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import it.sasabz.android.sasabus.classes.dbobjects.DBObject;
import java.util.Iterator;
import java.util.Vector;
/**
*
* MyListAdapter.java
*
*
* Copyright (C) 2012 Markus Windegger
*
* This file is part of SasaBus.
* SasaBus 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.
*
* SasaBus 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 SasaBus. If not, see <http://www.gnu.org/licenses/>.
*
*/
package it.sasabz.android.sasabus.classes.adapter;
/**
* @author Markus Windegger (markus@mowiso.com)
*
*/
public class MyAutocompleteAdapter extends BaseAdapter implements Filterable{
private final Context context; | private final Vector<DBObject> origlist; |
paolodongilli/SASAbus | src/it/sasabz/android/sasabus/classes/hafas/XMLRequest.java | // Path: src/it/sasabz/android/sasabus/SASAbus.java
// public class SASAbus extends Application {
// private int dbDownloadAttempts;
//
// private static Context context = null;
//
// @Override
// public void onCreate()
// {
// // Init values which could be loaded from files stored in res/raw
// setDbDownloadAttempts(0);
// super.onCreate();
// context = this.getApplicationContext();
// }
//
// @Override
// public void onTerminate()
// {
// //do nothing
// MySQLiteDBAdapter.closeAll();
// }
//
// /**
// * @return the Strings and Variables stored in the Context;
// */
// public static Context getContext()
// {
// return context;
// }
//
// /**
// * @param dbDownloadAttempts the dbDownloadAttempts to set
// */
// public void setDbDownloadAttempts(int dbDownloadAttempts) {
// this.dbDownloadAttempts = dbDownloadAttempts;
// }
//
// /**
// * @return the dbDownloadAttempts
// */
// public int getDbDownloadAttempts() {
// return dbDownloadAttempts;
// }
//
//
// }
//
// Path: src/it/sasabz/android/sasabus/classes/network/SASAbusXML.java
// public class SASAbusXML {
//
// public Document getDomElement(String xml)
// {
// Document doc = null;
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// try {
//
// DocumentBuilder db = dbf.newDocumentBuilder();
//
// InputSource is = new InputSource();
// is.setCharacterStream(new StringReader(xml));
// doc = db.parse(is);
//
// } catch (ParserConfigurationException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// } catch (SAXException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// } catch (IOException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// }
// return doc;
// }
//
//
// public String getValue(Element item, String str) {
// NodeList n = item.getElementsByTagName(str);
// return this.getElementValue(n.item(0));
// }
//
//
// public final String getElementValue( Node elem ) {
// Node child;
// if( elem != null){
// if (elem.hasChildNodes()){
// for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
// if( child.getNodeType() == Node.TEXT_NODE ){
// return child.getNodeValue();
// }
// }
// }
// }
// return "";
// }
//
// }
| import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import it.sasabz.android.sasabus.R;
import it.sasabz.android.sasabus.SASAbus;
import it.sasabz.android.sasabus.classes.network.SASAbusXML;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
| /**
*
* XMLRequest.java
*
*
* Copyright (C) 2012 Markus Windegger
*
* This file is part of SasaBus.
* SasaBus 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.
*
* SasaBus 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 SasaBus. If not, see <http://www.gnu.org/licenses/>.
*
*/
package it.sasabz.android.sasabus.classes.hafas;
public class XMLRequest {
/**
* Requests a validation of a Station via the xml Interface of SASA
* @param bahnhof
* @return
*/
public static String locValRequest(String bahnhof)
{
String xmlrequest = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"+
"<ReqC xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=" +
"\"http://hafassrv.hacon.de/xml/hafasXMLInterface.xsd\" prod=\"manuell\" ver=\"1.1\" lang=\"DE\" "+
| // Path: src/it/sasabz/android/sasabus/SASAbus.java
// public class SASAbus extends Application {
// private int dbDownloadAttempts;
//
// private static Context context = null;
//
// @Override
// public void onCreate()
// {
// // Init values which could be loaded from files stored in res/raw
// setDbDownloadAttempts(0);
// super.onCreate();
// context = this.getApplicationContext();
// }
//
// @Override
// public void onTerminate()
// {
// //do nothing
// MySQLiteDBAdapter.closeAll();
// }
//
// /**
// * @return the Strings and Variables stored in the Context;
// */
// public static Context getContext()
// {
// return context;
// }
//
// /**
// * @param dbDownloadAttempts the dbDownloadAttempts to set
// */
// public void setDbDownloadAttempts(int dbDownloadAttempts) {
// this.dbDownloadAttempts = dbDownloadAttempts;
// }
//
// /**
// * @return the dbDownloadAttempts
// */
// public int getDbDownloadAttempts() {
// return dbDownloadAttempts;
// }
//
//
// }
//
// Path: src/it/sasabz/android/sasabus/classes/network/SASAbusXML.java
// public class SASAbusXML {
//
// public Document getDomElement(String xml)
// {
// Document doc = null;
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// try {
//
// DocumentBuilder db = dbf.newDocumentBuilder();
//
// InputSource is = new InputSource();
// is.setCharacterStream(new StringReader(xml));
// doc = db.parse(is);
//
// } catch (ParserConfigurationException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// } catch (SAXException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// } catch (IOException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// }
// return doc;
// }
//
//
// public String getValue(Element item, String str) {
// NodeList n = item.getElementsByTagName(str);
// return this.getElementValue(n.item(0));
// }
//
//
// public final String getElementValue( Node elem ) {
// Node child;
// if( elem != null){
// if (elem.hasChildNodes()){
// for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
// if( child.getNodeType() == Node.TEXT_NODE ){
// return child.getNodeValue();
// }
// }
// }
// }
// return "";
// }
//
// }
// Path: src/it/sasabz/android/sasabus/classes/hafas/XMLRequest.java
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import it.sasabz.android.sasabus.R;
import it.sasabz.android.sasabus.SASAbus;
import it.sasabz.android.sasabus.classes.network.SASAbusXML;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
*
* XMLRequest.java
*
*
* Copyright (C) 2012 Markus Windegger
*
* This file is part of SasaBus.
* SasaBus 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.
*
* SasaBus 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 SasaBus. If not, see <http://www.gnu.org/licenses/>.
*
*/
package it.sasabz.android.sasabus.classes.hafas;
public class XMLRequest {
/**
* Requests a validation of a Station via the xml Interface of SASA
* @param bahnhof
* @return
*/
public static String locValRequest(String bahnhof)
{
String xmlrequest = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"+
"<ReqC xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=" +
"\"http://hafassrv.hacon.de/xml/hafasXMLInterface.xsd\" prod=\"manuell\" ver=\"1.1\" lang=\"DE\" "+
| "accessId=\"" + SASAbus.getContext().getResources().getString(R.string.accessId) + "\">\n<LocValReq id=\"toInput\" >\n" +
|
paolodongilli/SASAbus | src/it/sasabz/android/sasabus/classes/hafas/XMLRequest.java | // Path: src/it/sasabz/android/sasabus/SASAbus.java
// public class SASAbus extends Application {
// private int dbDownloadAttempts;
//
// private static Context context = null;
//
// @Override
// public void onCreate()
// {
// // Init values which could be loaded from files stored in res/raw
// setDbDownloadAttempts(0);
// super.onCreate();
// context = this.getApplicationContext();
// }
//
// @Override
// public void onTerminate()
// {
// //do nothing
// MySQLiteDBAdapter.closeAll();
// }
//
// /**
// * @return the Strings and Variables stored in the Context;
// */
// public static Context getContext()
// {
// return context;
// }
//
// /**
// * @param dbDownloadAttempts the dbDownloadAttempts to set
// */
// public void setDbDownloadAttempts(int dbDownloadAttempts) {
// this.dbDownloadAttempts = dbDownloadAttempts;
// }
//
// /**
// * @return the dbDownloadAttempts
// */
// public int getDbDownloadAttempts() {
// return dbDownloadAttempts;
// }
//
//
// }
//
// Path: src/it/sasabz/android/sasabus/classes/network/SASAbusXML.java
// public class SASAbusXML {
//
// public Document getDomElement(String xml)
// {
// Document doc = null;
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// try {
//
// DocumentBuilder db = dbf.newDocumentBuilder();
//
// InputSource is = new InputSource();
// is.setCharacterStream(new StringReader(xml));
// doc = db.parse(is);
//
// } catch (ParserConfigurationException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// } catch (SAXException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// } catch (IOException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// }
// return doc;
// }
//
//
// public String getValue(Element item, String str) {
// NodeList n = item.getElementsByTagName(str);
// return this.getElementValue(n.item(0));
// }
//
//
// public final String getElementValue( Node elem ) {
// Node child;
// if( elem != null){
// if (elem.hasChildNodes()){
// for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
// if( child.getNodeType() == Node.TEXT_NODE ){
// return child.getNodeValue();
// }
// }
// }
// }
// return "";
// }
//
// }
| import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import it.sasabz.android.sasabus.R;
import it.sasabz.android.sasabus.SASAbus;
import it.sasabz.android.sasabus.classes.network.SASAbusXML;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
| String ret = "";
if(!haveNetworkConnection())
{
return ret;
}
try {
HttpClient http = new DefaultHttpClient();
HttpPost post = new HttpPost(SASAbus.getContext().getString(R.string.xml_server));
StringEntity se = new StringEntity(xml, HTTP.UTF_8);
se.setContentType("text/xml");
post.setEntity(se);
HttpResponse response = http.execute(post);
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
ret = EntityUtils.toString(response.getEntity());
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
public static boolean containsError(String xml)
{
| // Path: src/it/sasabz/android/sasabus/SASAbus.java
// public class SASAbus extends Application {
// private int dbDownloadAttempts;
//
// private static Context context = null;
//
// @Override
// public void onCreate()
// {
// // Init values which could be loaded from files stored in res/raw
// setDbDownloadAttempts(0);
// super.onCreate();
// context = this.getApplicationContext();
// }
//
// @Override
// public void onTerminate()
// {
// //do nothing
// MySQLiteDBAdapter.closeAll();
// }
//
// /**
// * @return the Strings and Variables stored in the Context;
// */
// public static Context getContext()
// {
// return context;
// }
//
// /**
// * @param dbDownloadAttempts the dbDownloadAttempts to set
// */
// public void setDbDownloadAttempts(int dbDownloadAttempts) {
// this.dbDownloadAttempts = dbDownloadAttempts;
// }
//
// /**
// * @return the dbDownloadAttempts
// */
// public int getDbDownloadAttempts() {
// return dbDownloadAttempts;
// }
//
//
// }
//
// Path: src/it/sasabz/android/sasabus/classes/network/SASAbusXML.java
// public class SASAbusXML {
//
// public Document getDomElement(String xml)
// {
// Document doc = null;
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// try {
//
// DocumentBuilder db = dbf.newDocumentBuilder();
//
// InputSource is = new InputSource();
// is.setCharacterStream(new StringReader(xml));
// doc = db.parse(is);
//
// } catch (ParserConfigurationException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// } catch (SAXException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// } catch (IOException e) {
// Log.e("Error: ", e.getMessage());
// return null;
// }
// return doc;
// }
//
//
// public String getValue(Element item, String str) {
// NodeList n = item.getElementsByTagName(str);
// return this.getElementValue(n.item(0));
// }
//
//
// public final String getElementValue( Node elem ) {
// Node child;
// if( elem != null){
// if (elem.hasChildNodes()){
// for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){
// if( child.getNodeType() == Node.TEXT_NODE ){
// return child.getNodeValue();
// }
// }
// }
// }
// return "";
// }
//
// }
// Path: src/it/sasabz/android/sasabus/classes/hafas/XMLRequest.java
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import it.sasabz.android.sasabus.R;
import it.sasabz.android.sasabus.SASAbus;
import it.sasabz.android.sasabus.classes.network.SASAbusXML;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
String ret = "";
if(!haveNetworkConnection())
{
return ret;
}
try {
HttpClient http = new DefaultHttpClient();
HttpPost post = new HttpPost(SASAbus.getContext().getString(R.string.xml_server));
StringEntity se = new StringEntity(xml, HTTP.UTF_8);
se.setContentType("text/xml");
post.setEntity(se);
HttpResponse response = http.execute(post);
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
ret = EntityUtils.toString(response.getEntity());
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
public static boolean containsError(String xml)
{
| SASAbusXML parser = new SASAbusXML();
|
paolodongilli/SASAbus | src/it/sasabz/android/sasabus/SASAbus.java | // Path: src/it/sasabz/android/sasabus/classes/adapter/MySQLiteDBAdapter.java
// public class MySQLiteDBAdapter {
//
// private static SQLiteDatabase sqlite= null;
// private static DatabaseHelper helper = null;
// private static int counteropen = 0;
// private static int transactioncounter = 0;
//
// public static boolean exists(Context context)
// {
// String appName = context.getResources().getString(R.string.app_name_db);
// String dbFileName = appName + ".db";
// if(helper == null)
// {
// helper = new DatabaseHelper(dbFileName, null);
// }
// if(!helper.databaseFileExists())
// return false;
// return true;
// }
//
// /**
// * This static method allows you tu getting an instance of the current database
// * @param context is the actual context
// * @return an opened and read only sqlite database
// */
// public static MySQLiteDBAdapter getInstance(Context context)
// {
// if(counteropen == 0)
// {
// Resources res = context.getResources();
// String appName = res.getString(R.string.app_name_db);
// String dbFileName = appName + ".db";
// if(helper == null)
// helper = new DatabaseHelper(dbFileName,null);
// sqlite = helper.getReadableDatabase();
// if(sqlite == null)
// {
// System.err.println("Die Datenbank konnte nicht geoeffnet werden");
// System.exit(-2);
// }
// }
// ++counteropen;
// return new MySQLiteDBAdapter();
// }
//
// /**
// * makes the constructor private and so the only way to obtain an instance
// * of the object is the static method getInstance
// */
// private MySQLiteDBAdapter()
// {
// //do nothing
// }
//
// /**
// * This method closes all open MySQLiteDBAdapter
// */
// public static void closeAll()
// {
// helper.close();
// sqlite.close();
// }
//
// /**
// * This method "closes" the database. There is a counter, because when there are more then one
// * instance, then the db will not be closed, it will be decrementet only the counter.
// * when the counter is 0, then the database will be closed
// */
// public void close()
// {
// --counteropen;
// if(counteropen == 0)
// {
// helper.close();
// sqlite.close();
// }
// }
//
// /**
// * This method allows you to query the database
// * @param query is the query to send
// * @param args are the arguments for the query
// * @return a cursor to the result set of the query
// */
// public Cursor rawQuery(String query, String[] args)
// {
// Cursor ret = null;
// ret = sqlite.rawQuery(query, args);
// return ret;
// }
//
// /**
// * to work with transaction management, and to provide it with the idea
// * of the singleton pattern, there is a counter that counts the transactions open
// * because the database can handle only one transaction open per dbfile
// */
// public void beginTransaction()
// {
// if(transactioncounter == 0)
// {
// sqlite.beginTransaction();
// }
// transactioncounter++;
//
// }
//
// /**
// * to work with transaction management, and to provide it with the idea
// * of the singleton pattern, there is a counter that counts the transactions closed
// * because the database can handle only one transaction open per dbfile
// */
// public void endTransaction()
// {
// transactioncounter--;
// if(transactioncounter == 0)
// {
// sqlite.endTransaction();
// }
// }
//
// /**
// * This classes helps to open the database read only and close it correctly after using
// * @author Markus Windegger (markus@mowiso.com)
// *
// */
// private static class DatabaseHelper extends DBFileManager {
//
// DatabaseHelper(String dbFileName, SQLiteDatabase.CursorFactory factory) {
// super(dbFileName, factory);
// }
// }
//
// }
| import it.sasabz.android.sasabus.classes.adapter.MySQLiteDBAdapter;
import android.app.Application;
import android.content.Context;
import android.content.res.Resources; | /**
*
* SASAbus.java
*
* Created: Dec 4, 2011 12:32:09 PM
*
* Copyright (C) 2011 Paolo Dongilli and Markus Windegger
*
* This file is part of SASAbus.
* SASAbus 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.
*
* SASAbus 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 SASAbus. If not, see <http://www.gnu.org/licenses/>.
*
*/
package it.sasabz.android.sasabus;
public class SASAbus extends Application {
private int dbDownloadAttempts;
private static Context context = null;
@Override
public void onCreate()
{
// Init values which could be loaded from files stored in res/raw
setDbDownloadAttempts(0);
super.onCreate();
context = this.getApplicationContext();
}
@Override
public void onTerminate()
{
//do nothing | // Path: src/it/sasabz/android/sasabus/classes/adapter/MySQLiteDBAdapter.java
// public class MySQLiteDBAdapter {
//
// private static SQLiteDatabase sqlite= null;
// private static DatabaseHelper helper = null;
// private static int counteropen = 0;
// private static int transactioncounter = 0;
//
// public static boolean exists(Context context)
// {
// String appName = context.getResources().getString(R.string.app_name_db);
// String dbFileName = appName + ".db";
// if(helper == null)
// {
// helper = new DatabaseHelper(dbFileName, null);
// }
// if(!helper.databaseFileExists())
// return false;
// return true;
// }
//
// /**
// * This static method allows you tu getting an instance of the current database
// * @param context is the actual context
// * @return an opened and read only sqlite database
// */
// public static MySQLiteDBAdapter getInstance(Context context)
// {
// if(counteropen == 0)
// {
// Resources res = context.getResources();
// String appName = res.getString(R.string.app_name_db);
// String dbFileName = appName + ".db";
// if(helper == null)
// helper = new DatabaseHelper(dbFileName,null);
// sqlite = helper.getReadableDatabase();
// if(sqlite == null)
// {
// System.err.println("Die Datenbank konnte nicht geoeffnet werden");
// System.exit(-2);
// }
// }
// ++counteropen;
// return new MySQLiteDBAdapter();
// }
//
// /**
// * makes the constructor private and so the only way to obtain an instance
// * of the object is the static method getInstance
// */
// private MySQLiteDBAdapter()
// {
// //do nothing
// }
//
// /**
// * This method closes all open MySQLiteDBAdapter
// */
// public static void closeAll()
// {
// helper.close();
// sqlite.close();
// }
//
// /**
// * This method "closes" the database. There is a counter, because when there are more then one
// * instance, then the db will not be closed, it will be decrementet only the counter.
// * when the counter is 0, then the database will be closed
// */
// public void close()
// {
// --counteropen;
// if(counteropen == 0)
// {
// helper.close();
// sqlite.close();
// }
// }
//
// /**
// * This method allows you to query the database
// * @param query is the query to send
// * @param args are the arguments for the query
// * @return a cursor to the result set of the query
// */
// public Cursor rawQuery(String query, String[] args)
// {
// Cursor ret = null;
// ret = sqlite.rawQuery(query, args);
// return ret;
// }
//
// /**
// * to work with transaction management, and to provide it with the idea
// * of the singleton pattern, there is a counter that counts the transactions open
// * because the database can handle only one transaction open per dbfile
// */
// public void beginTransaction()
// {
// if(transactioncounter == 0)
// {
// sqlite.beginTransaction();
// }
// transactioncounter++;
//
// }
//
// /**
// * to work with transaction management, and to provide it with the idea
// * of the singleton pattern, there is a counter that counts the transactions closed
// * because the database can handle only one transaction open per dbfile
// */
// public void endTransaction()
// {
// transactioncounter--;
// if(transactioncounter == 0)
// {
// sqlite.endTransaction();
// }
// }
//
// /**
// * This classes helps to open the database read only and close it correctly after using
// * @author Markus Windegger (markus@mowiso.com)
// *
// */
// private static class DatabaseHelper extends DBFileManager {
//
// DatabaseHelper(String dbFileName, SQLiteDatabase.CursorFactory factory) {
// super(dbFileName, factory);
// }
// }
//
// }
// Path: src/it/sasabz/android/sasabus/SASAbus.java
import it.sasabz.android.sasabus.classes.adapter.MySQLiteDBAdapter;
import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
/**
*
* SASAbus.java
*
* Created: Dec 4, 2011 12:32:09 PM
*
* Copyright (C) 2011 Paolo Dongilli and Markus Windegger
*
* This file is part of SASAbus.
* SASAbus 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.
*
* SASAbus 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 SASAbus. If not, see <http://www.gnu.org/licenses/>.
*
*/
package it.sasabz.android.sasabus;
public class SASAbus extends Application {
private int dbDownloadAttempts;
private static Context context = null;
@Override
public void onCreate()
{
// Init values which could be loaded from files stored in res/raw
setDbDownloadAttempts(0);
super.onCreate();
context = this.getApplicationContext();
}
@Override
public void onTerminate()
{
//do nothing | MySQLiteDBAdapter.closeAll(); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataService.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List; | package net.seleucus.wsp.crypto.fwknop;
public class TestDataService {
public static final String TEST_DATA_FILE = "/data/fwknop/test_data.csv";
public static List<TestDataRow> getTestData() throws Exception {
final List<TestDataRow> rows = new ArrayList<>();
for(String line : IOUtils.readLines(TestDataService.class.getResourceAsStream(TEST_DATA_FILE))){
final String[] fields = StringUtils.split(line, ';');
final TestDataRow testDataRow = new TestDataRow();
testDataRow.setEncryptionKey(Hex.decodeHex(fields[0].toCharArray()));
testDataRow.setSignatureKey(Hex.decodeHex(fields[1].toCharArray())); | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
// Path: src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataService.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
package net.seleucus.wsp.crypto.fwknop;
public class TestDataService {
public static final String TEST_DATA_FILE = "/data/fwknop/test_data.csv";
public static List<TestDataRow> getTestData() throws Exception {
final List<TestDataRow> rows = new ArrayList<>();
for(String line : IOUtils.readLines(TestDataService.class.getResourceAsStream(TEST_DATA_FILE))){
final String[] fields = StringUtils.split(line, ';');
final TestDataRow testDataRow = new TestDataRow();
testDataRow.setEncryptionKey(Hex.decodeHex(fields[0].toCharArray()));
testDataRow.setSignatureKey(Hex.decodeHex(fields[1].toCharArray())); | testDataRow.setDigestType(DigestType.valueOf(fields[2])); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataService.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List; | package net.seleucus.wsp.crypto.fwknop;
public class TestDataService {
public static final String TEST_DATA_FILE = "/data/fwknop/test_data.csv";
public static List<TestDataRow> getTestData() throws Exception {
final List<TestDataRow> rows = new ArrayList<>();
for(String line : IOUtils.readLines(TestDataService.class.getResourceAsStream(TEST_DATA_FILE))){
final String[] fields = StringUtils.split(line, ';');
final TestDataRow testDataRow = new TestDataRow();
testDataRow.setEncryptionKey(Hex.decodeHex(fields[0].toCharArray()));
testDataRow.setSignatureKey(Hex.decodeHex(fields[1].toCharArray()));
testDataRow.setDigestType(DigestType.valueOf(fields[2])); | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
// Path: src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataService.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
package net.seleucus.wsp.crypto.fwknop;
public class TestDataService {
public static final String TEST_DATA_FILE = "/data/fwknop/test_data.csv";
public static List<TestDataRow> getTestData() throws Exception {
final List<TestDataRow> rows = new ArrayList<>();
for(String line : IOUtils.readLines(TestDataService.class.getResourceAsStream(TEST_DATA_FILE))){
final String[] fields = StringUtils.split(line, ';');
final TestDataRow testDataRow = new TestDataRow();
testDataRow.setEncryptionKey(Hex.decodeHex(fields[0].toCharArray()));
testDataRow.setSignatureKey(Hex.decodeHex(fields[1].toCharArray()));
testDataRow.setDigestType(DigestType.valueOf(fields[2])); | testDataRow.setHmacType(HmacType.valueOf("Hmac" + fields[3])); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataService.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List; | package net.seleucus.wsp.crypto.fwknop;
public class TestDataService {
public static final String TEST_DATA_FILE = "/data/fwknop/test_data.csv";
public static List<TestDataRow> getTestData() throws Exception {
final List<TestDataRow> rows = new ArrayList<>();
for(String line : IOUtils.readLines(TestDataService.class.getResourceAsStream(TEST_DATA_FILE))){
final String[] fields = StringUtils.split(line, ';');
final TestDataRow testDataRow = new TestDataRow();
testDataRow.setEncryptionKey(Hex.decodeHex(fields[0].toCharArray()));
testDataRow.setSignatureKey(Hex.decodeHex(fields[1].toCharArray()));
testDataRow.setDigestType(DigestType.valueOf(fields[2]));
testDataRow.setHmacType(HmacType.valueOf("Hmac" + fields[3]));
testDataRow.setRandomValue(Long.valueOf(fields[4]));
testDataRow.setUserName(fields[5]);
testDataRow.setTimestamp(Long.valueOf(fields[6]));
testDataRow.setVersion(fields[7]); | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
// Path: src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataService.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
package net.seleucus.wsp.crypto.fwknop;
public class TestDataService {
public static final String TEST_DATA_FILE = "/data/fwknop/test_data.csv";
public static List<TestDataRow> getTestData() throws Exception {
final List<TestDataRow> rows = new ArrayList<>();
for(String line : IOUtils.readLines(TestDataService.class.getResourceAsStream(TEST_DATA_FILE))){
final String[] fields = StringUtils.split(line, ';');
final TestDataRow testDataRow = new TestDataRow();
testDataRow.setEncryptionKey(Hex.decodeHex(fields[0].toCharArray()));
testDataRow.setSignatureKey(Hex.decodeHex(fields[1].toCharArray()));
testDataRow.setDigestType(DigestType.valueOf(fields[2]));
testDataRow.setHmacType(HmacType.valueOf("Hmac" + fields[3]));
testDataRow.setRandomValue(Long.valueOf(fields[4]));
testDataRow.setUserName(fields[5]);
testDataRow.setTimestamp(Long.valueOf(fields[6]));
testDataRow.setVersion(fields[7]); | testDataRow.setMessageType(MessageType.values()[Integer.valueOf(fields[8])]); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/listener/WebServerLogTailCallbackListener.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilterService.java
// public interface WebLogFilterService {
//
// FilterResult isFiltered(final LogMessage logMessage);
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogLineParser.java
// public interface LogLineParser {
//
// LogMessage parse(final String line) throws LogParseException;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogParseException.java
// public class LogParseException extends ParametrisedMessageException {
//
// public LogParseException(String message, Object... arguments) {
// super(message, arguments);
// }
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilterService;
import net.seleucus.wsp.server.request.parser.LogLineParser;
import net.seleucus.wsp.server.request.parser.LogParseException;
import org.apache.commons.io.input.TailerListenerAdapter;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT; | package net.seleucus.wsp.server.listener;
public class WebServerLogTailCallbackListener extends TailerListenerAdapter {
private final LogLineParser logParser; | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilterService.java
// public interface WebLogFilterService {
//
// FilterResult isFiltered(final LogMessage logMessage);
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogLineParser.java
// public interface LogLineParser {
//
// LogMessage parse(final String line) throws LogParseException;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogParseException.java
// public class LogParseException extends ParametrisedMessageException {
//
// public LogParseException(String message, Object... arguments) {
// super(message, arguments);
// }
// }
// Path: src/main/java/net/seleucus/wsp/server/listener/WebServerLogTailCallbackListener.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilterService;
import net.seleucus.wsp.server.request.parser.LogLineParser;
import net.seleucus.wsp.server.request.parser.LogParseException;
import org.apache.commons.io.input.TailerListenerAdapter;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
package net.seleucus.wsp.server.listener;
public class WebServerLogTailCallbackListener extends TailerListenerAdapter {
private final LogLineParser logParser; | private final WebLogFilterService webLogFilterService; |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/listener/WebServerLogTailCallbackListener.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilterService.java
// public interface WebLogFilterService {
//
// FilterResult isFiltered(final LogMessage logMessage);
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogLineParser.java
// public interface LogLineParser {
//
// LogMessage parse(final String line) throws LogParseException;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogParseException.java
// public class LogParseException extends ParametrisedMessageException {
//
// public LogParseException(String message, Object... arguments) {
// super(message, arguments);
// }
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilterService;
import net.seleucus.wsp.server.request.parser.LogLineParser;
import net.seleucus.wsp.server.request.parser.LogParseException;
import org.apache.commons.io.input.TailerListenerAdapter;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT; | package net.seleucus.wsp.server.listener;
public class WebServerLogTailCallbackListener extends TailerListenerAdapter {
private final LogLineParser logParser;
private final WebLogFilterService webLogFilterService;
public WebServerLogTailCallbackListener(final LogLineParser logParser, final WebLogFilterService webLogFilterService) {
this.logParser = logParser;
this.webLogFilterService = webLogFilterService;
}
@Override
public void handle(final String line) {
try { | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilterService.java
// public interface WebLogFilterService {
//
// FilterResult isFiltered(final LogMessage logMessage);
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogLineParser.java
// public interface LogLineParser {
//
// LogMessage parse(final String line) throws LogParseException;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogParseException.java
// public class LogParseException extends ParametrisedMessageException {
//
// public LogParseException(String message, Object... arguments) {
// super(message, arguments);
// }
// }
// Path: src/main/java/net/seleucus/wsp/server/listener/WebServerLogTailCallbackListener.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilterService;
import net.seleucus.wsp.server.request.parser.LogLineParser;
import net.seleucus.wsp.server.request.parser.LogParseException;
import org.apache.commons.io.input.TailerListenerAdapter;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
package net.seleucus.wsp.server.listener;
public class WebServerLogTailCallbackListener extends TailerListenerAdapter {
private final LogLineParser logParser;
private final WebLogFilterService webLogFilterService;
public WebServerLogTailCallbackListener(final LogLineParser logParser, final WebLogFilterService webLogFilterService) {
this.logParser = logParser;
this.webLogFilterService = webLogFilterService;
}
@Override
public void handle(final String line) {
try { | final LogMessage logMessage = logParser.parse(line); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/listener/WebServerLogTailCallbackListener.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilterService.java
// public interface WebLogFilterService {
//
// FilterResult isFiltered(final LogMessage logMessage);
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogLineParser.java
// public interface LogLineParser {
//
// LogMessage parse(final String line) throws LogParseException;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogParseException.java
// public class LogParseException extends ParametrisedMessageException {
//
// public LogParseException(String message, Object... arguments) {
// super(message, arguments);
// }
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilterService;
import net.seleucus.wsp.server.request.parser.LogLineParser;
import net.seleucus.wsp.server.request.parser.LogParseException;
import org.apache.commons.io.input.TailerListenerAdapter;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT; | package net.seleucus.wsp.server.listener;
public class WebServerLogTailCallbackListener extends TailerListenerAdapter {
private final LogLineParser logParser;
private final WebLogFilterService webLogFilterService;
public WebServerLogTailCallbackListener(final LogLineParser logParser, final WebLogFilterService webLogFilterService) {
this.logParser = logParser;
this.webLogFilterService = webLogFilterService;
}
@Override
public void handle(final String line) {
try {
final LogMessage logMessage = logParser.parse(line);
if(webLogFilterService.isFiltered(logMessage) == ACCEPT){
// send the logMessage for further processing
} | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilterService.java
// public interface WebLogFilterService {
//
// FilterResult isFiltered(final LogMessage logMessage);
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogLineParser.java
// public interface LogLineParser {
//
// LogMessage parse(final String line) throws LogParseException;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/parser/LogParseException.java
// public class LogParseException extends ParametrisedMessageException {
//
// public LogParseException(String message, Object... arguments) {
// super(message, arguments);
// }
// }
// Path: src/main/java/net/seleucus/wsp/server/listener/WebServerLogTailCallbackListener.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilterService;
import net.seleucus.wsp.server.request.parser.LogLineParser;
import net.seleucus.wsp.server.request.parser.LogParseException;
import org.apache.commons.io.input.TailerListenerAdapter;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
package net.seleucus.wsp.server.listener;
public class WebServerLogTailCallbackListener extends TailerListenerAdapter {
private final LogLineParser logParser;
private final WebLogFilterService webLogFilterService;
public WebServerLogTailCallbackListener(final LogLineParser logParser, final WebLogFilterService webLogFilterService) {
this.logParser = logParser;
this.webLogFilterService = webLogFilterService;
}
@Override
public void handle(final String line) {
try {
final LogMessage logMessage = logParser.parse(line);
if(webLogFilterService.isFiltered(logMessage) == ACCEPT){
// send the logMessage for further processing
} | } catch (LogParseException e) { |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/main/WebSpaTest.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/CommandLineArgument.java
// public enum CommandLineArgument {
//
// SHOW_HELP("-help", "Print this usage message"),
// CLIENT_MODE("-client", "Run the client, generate valid requests"),
// SERVER_MODE("-server", "Run the server"),
// SHOW_VERSION("-version", "Display application version number"),
// START("-start", "Start the daemon service"),
// STOP("-stop", "Stop the daemon service"),
// SHOW_STATUS("-status", "Display the status of the daemon service");
//
// private static final Map<String, CommandLineArgument> ARGUMENTS_BY_NAME = new HashMap<>(values().length);
//
// static {
// for(final CommandLineArgument arg: values()){
// ARGUMENTS_BY_NAME.put(arg.getName().toLowerCase(), arg);
// }
// }
//
// public static CommandLineArgument getByName(final String name){
// return ARGUMENTS_BY_NAME.get(StringUtils.lowerCase(name));
// }
//
// private final String name;
// private final String description;
//
// private CommandLineArgument(final String name, final String description) {
// this.name = name;
// this.description = description;
// }
//
// public String getName() {
// return name;
// }
//
// public String getDescription() {
// return description;
// }
// }
| import net.seleucus.wsp.console.WSConsole;
import org.junit.Test;
import static net.seleucus.wsp.main.CommandLineArgument.*;
import static org.junit.Assert.assertEquals; | package net.seleucus.wsp.main;
public class WebSpaTest {
@Test
public void testProcessParametersReturnsMinusTwoIfNoArguments() { | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/CommandLineArgument.java
// public enum CommandLineArgument {
//
// SHOW_HELP("-help", "Print this usage message"),
// CLIENT_MODE("-client", "Run the client, generate valid requests"),
// SERVER_MODE("-server", "Run the server"),
// SHOW_VERSION("-version", "Display application version number"),
// START("-start", "Start the daemon service"),
// STOP("-stop", "Stop the daemon service"),
// SHOW_STATUS("-status", "Display the status of the daemon service");
//
// private static final Map<String, CommandLineArgument> ARGUMENTS_BY_NAME = new HashMap<>(values().length);
//
// static {
// for(final CommandLineArgument arg: values()){
// ARGUMENTS_BY_NAME.put(arg.getName().toLowerCase(), arg);
// }
// }
//
// public static CommandLineArgument getByName(final String name){
// return ARGUMENTS_BY_NAME.get(StringUtils.lowerCase(name));
// }
//
// private final String name;
// private final String description;
//
// private CommandLineArgument(final String name, final String description) {
// this.name = name;
// this.description = description;
// }
//
// public String getName() {
// return name;
// }
//
// public String getDescription() {
// return description;
// }
// }
// Path: src/test/java/net/seleucus/wsp/main/WebSpaTest.java
import net.seleucus.wsp.console.WSConsole;
import org.junit.Test;
import static net.seleucus.wsp.main.CommandLineArgument.*;
import static org.junit.Assert.assertEquals;
package net.seleucus.wsp.main;
public class WebSpaTest {
@Test
public void testProcessParametersReturnsMinusTwoIfNoArguments() { | final WebSpa myWebSpa = new WebSpa(WSConsole.getWsConsole()); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/client/WSRequestBuilder.java | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaEncoder.java
// public class WebSpaEncoder {
//
// private CharSequence passPhrase;
// private int actionNumber;
//
// public WebSpaEncoder(CharSequence passPhrase, int actionNumber) {
// this.passPhrase = passPhrase;
// this.actionNumber = actionNumber;
// }
//
// public String getKnock() {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// byte[] actionKnockBytes = ActionNumberCrypto.getHashedActionNumberNow(passPhrase, actionNumber);
//
// byte[] allBytes = ArrayUtils.addAll(passKnockBytes, actionKnockBytes);
//
// return Base64.encodeBase64URLSafeString(allBytes);
// }
//
// public static String encode(CharSequence passPhrase) {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// return Base64.encodeBase64URLSafeString(passKnockBytes);
// }
//
// public static boolean matches(CharSequence rawPassword, String webSpaRequest) {
//
// if(webSpaRequest.length() != 100) {
//
// return false;
//
// } else {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] passBytes = ArrayUtils.subarray(webSpaBytes, 0, 51);
// byte randomByte = webSpaBytes[0];
//
// byte[] expectedBytes = PassPhraseCrypto.getHashedPassPhraseNowWithSalt(rawPassword, randomByte);
//
// return WebSpaUtils.equals(passBytes, expectedBytes);
// }
// }
//
// public static int getActionNumber(CharSequence rawPassword, String webSpaRequest) {
//
// int returnAction = -1;
//
// if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] actionBytes = ArrayUtils.subarray(webSpaBytes, 51, 75);
// byte[] actionSalt = ArrayUtils.subarray(actionBytes, 0, 4);
//
// for(int count = 0; count <= 9; count++) {
//
// byte[] calculatedActionBytes =
// ActionNumberCrypto.getHashedActionNumberNowWithSalt(rawPassword, count, actionSalt);
//
// if(WebSpaUtils.equals(calculatedActionBytes, actionBytes)) {
// returnAction = count;
// break;
// }
//
// } // for loop
// }
//
// return returnAction;
// }
//
// }
| import net.seleucus.wsp.crypto.WebSpaEncoder; | package net.seleucus.wsp.client;
public class WSRequestBuilder {
private final String host;
private final String knock;
public WSRequestBuilder(final String host, CharSequence password, int action) {
this.host = host; | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaEncoder.java
// public class WebSpaEncoder {
//
// private CharSequence passPhrase;
// private int actionNumber;
//
// public WebSpaEncoder(CharSequence passPhrase, int actionNumber) {
// this.passPhrase = passPhrase;
// this.actionNumber = actionNumber;
// }
//
// public String getKnock() {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// byte[] actionKnockBytes = ActionNumberCrypto.getHashedActionNumberNow(passPhrase, actionNumber);
//
// byte[] allBytes = ArrayUtils.addAll(passKnockBytes, actionKnockBytes);
//
// return Base64.encodeBase64URLSafeString(allBytes);
// }
//
// public static String encode(CharSequence passPhrase) {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// return Base64.encodeBase64URLSafeString(passKnockBytes);
// }
//
// public static boolean matches(CharSequence rawPassword, String webSpaRequest) {
//
// if(webSpaRequest.length() != 100) {
//
// return false;
//
// } else {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] passBytes = ArrayUtils.subarray(webSpaBytes, 0, 51);
// byte randomByte = webSpaBytes[0];
//
// byte[] expectedBytes = PassPhraseCrypto.getHashedPassPhraseNowWithSalt(rawPassword, randomByte);
//
// return WebSpaUtils.equals(passBytes, expectedBytes);
// }
// }
//
// public static int getActionNumber(CharSequence rawPassword, String webSpaRequest) {
//
// int returnAction = -1;
//
// if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] actionBytes = ArrayUtils.subarray(webSpaBytes, 51, 75);
// byte[] actionSalt = ArrayUtils.subarray(actionBytes, 0, 4);
//
// for(int count = 0; count <= 9; count++) {
//
// byte[] calculatedActionBytes =
// ActionNumberCrypto.getHashedActionNumberNowWithSalt(rawPassword, count, actionSalt);
//
// if(WebSpaUtils.equals(calculatedActionBytes, actionBytes)) {
// returnAction = count;
// break;
// }
//
// } // for loop
// }
//
// return returnAction;
// }
//
// }
// Path: src/main/java/net/seleucus/wsp/client/WSRequestBuilder.java
import net.seleucus.wsp.crypto.WebSpaEncoder;
package net.seleucus.wsp.client;
public class WSRequestBuilder {
private final String host;
private final String knock;
public WSRequestBuilder(final String host, CharSequence password, int action) {
this.host = host; | WebSpaEncoder wsEncoder = new WebSpaEncoder(password, action); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilter.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.apache.commons.lang3.StringUtils; | package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilter implements WebLogFilter {
private final int minLength;
private final int maxLength;
public UriLengthWebLogFilter(final int minLength, final int maxLength) {
this.minLength = minLength;
this.maxLength = maxLength;
}
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilter.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.apache.commons.lang3.StringUtils;
package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilter implements WebLogFilter {
private final int minLength;
private final int maxLength;
public UriLengthWebLogFilter(final int minLength, final int maxLength) {
this.minLength = minLength;
this.maxLength = maxLength;
}
@Override | public FilterResult parse(final LogMessage logMessage) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilter.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.apache.commons.lang3.StringUtils; | package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilter implements WebLogFilter {
private final int minLength;
private final int maxLength;
public UriLengthWebLogFilter(final int minLength, final int maxLength) {
this.minLength = minLength;
this.maxLength = maxLength;
}
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilter.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.apache.commons.lang3.StringUtils;
package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilter implements WebLogFilter {
private final int minLength;
private final int maxLength;
public UriLengthWebLogFilter(final int minLength, final int maxLength) {
this.minLength = minLength;
this.maxLength = maxLength;
}
@Override | public FilterResult parse(final LogMessage logMessage) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/filters/HttpMethodWebLogFilter.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/HttpMethod.java
// public enum HttpMethod {
//
// GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
| import com.google.common.collect.ImmutableSet;
import net.seleucus.wsp.server.request.domain.HttpMethod;
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import java.util.Set; | package net.seleucus.wsp.server.request.filter.filters;
public class HttpMethodWebLogFilter implements WebLogFilter {
private final Set<HttpMethod> allowedHttpMethods;
public HttpMethodWebLogFilter(Set<HttpMethod> allowedHttpMethods) {
this.allowedHttpMethods = ImmutableSet.copyOf(allowedHttpMethods);
}
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/HttpMethod.java
// public enum HttpMethod {
//
// GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/filters/HttpMethodWebLogFilter.java
import com.google.common.collect.ImmutableSet;
import net.seleucus.wsp.server.request.domain.HttpMethod;
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import java.util.Set;
package net.seleucus.wsp.server.request.filter.filters;
public class HttpMethodWebLogFilter implements WebLogFilter {
private final Set<HttpMethod> allowedHttpMethods;
public HttpMethodWebLogFilter(Set<HttpMethod> allowedHttpMethods) {
this.allowedHttpMethods = ImmutableSet.copyOf(allowedHttpMethods);
}
@Override | public FilterResult parse(LogMessage logMessage) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/filters/HttpMethodWebLogFilter.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/HttpMethod.java
// public enum HttpMethod {
//
// GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
| import com.google.common.collect.ImmutableSet;
import net.seleucus.wsp.server.request.domain.HttpMethod;
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import java.util.Set; | package net.seleucus.wsp.server.request.filter.filters;
public class HttpMethodWebLogFilter implements WebLogFilter {
private final Set<HttpMethod> allowedHttpMethods;
public HttpMethodWebLogFilter(Set<HttpMethod> allowedHttpMethods) {
this.allowedHttpMethods = ImmutableSet.copyOf(allowedHttpMethods);
}
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/HttpMethod.java
// public enum HttpMethod {
//
// GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/filters/HttpMethodWebLogFilter.java
import com.google.common.collect.ImmutableSet;
import net.seleucus.wsp.server.request.domain.HttpMethod;
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import java.util.Set;
package net.seleucus.wsp.server.request.filter.filters;
public class HttpMethodWebLogFilter implements WebLogFilter {
private final Set<HttpMethod> allowedHttpMethods;
public HttpMethodWebLogFilter(Set<HttpMethod> allowedHttpMethods) {
this.allowedHttpMethods = ImmutableSet.copyOf(allowedHttpMethods);
}
@Override | public FilterResult parse(LogMessage logMessage) { |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/request/filter/filters/HttpMethodWebLogFilterTest.java | // Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/HttpMethod.java
// public enum HttpMethod {
//
// GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
| import com.google.common.collect.ImmutableSet;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.HttpMethod.*;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.fest.assertions.api.Assertions.assertThat; | package net.seleucus.wsp.server.request.filter.filters;
public class HttpMethodWebLogFilterTest {
@Test
public void testParse() throws Exception { | // Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/HttpMethod.java
// public enum HttpMethod {
//
// GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
// Path: src/test/java/net/seleucus/wsp/server/request/filter/filters/HttpMethodWebLogFilterTest.java
import com.google.common.collect.ImmutableSet;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.HttpMethod.*;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.fest.assertions.api.Assertions.assertThat;
package net.seleucus.wsp.server.request.filter.filters;
public class HttpMethodWebLogFilterTest {
@Test
public void testParse() throws Exception { | final WebLogFilter filter = new HttpMethodWebLogFilter(ImmutableSet.of(GET, POST)); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/request/filter/filters/HttpMethodWebLogFilterTest.java | // Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/HttpMethod.java
// public enum HttpMethod {
//
// GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
| import com.google.common.collect.ImmutableSet;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.HttpMethod.*;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.fest.assertions.api.Assertions.assertThat; | package net.seleucus.wsp.server.request.filter.filters;
public class HttpMethodWebLogFilterTest {
@Test
public void testParse() throws Exception {
final WebLogFilter filter = new HttpMethodWebLogFilter(ImmutableSet.of(GET, POST)); | // Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/HttpMethod.java
// public enum HttpMethod {
//
// GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT;
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
// Path: src/test/java/net/seleucus/wsp/server/request/filter/filters/HttpMethodWebLogFilterTest.java
import com.google.common.collect.ImmutableSet;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.HttpMethod.*;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.fest.assertions.api.Assertions.assertThat;
package net.seleucus.wsp.server.request.filter.filters;
public class HttpMethodWebLogFilterTest {
@Test
public void testParse() throws Exception {
final WebLogFilter filter = new HttpMethodWebLogFilter(ImmutableSet.of(GET, POST)); | assertThat(filter.parse(createLogMessage().withHttpMethod(GET).build())).isEqualTo(ACCEPT); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/ChainingWebLogFilterService.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
| import com.google.common.collect.ImmutableList;
import net.seleucus.wsp.server.request.domain.LogMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT; | package net.seleucus.wsp.server.request.filter;
public class ChainingWebLogFilterService implements WebLogFilterService {
private final Logger logger = LoggerFactory.getLogger(ChainingWebLogFilterService.class);
private final List<WebLogFilter> filters;
public ChainingWebLogFilterService(final List<WebLogFilter> validators) {
this.filters = ImmutableList.copyOf(validators);
}
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/ChainingWebLogFilterService.java
import com.google.common.collect.ImmutableList;
import net.seleucus.wsp.server.request.domain.LogMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
package net.seleucus.wsp.server.request.filter;
public class ChainingWebLogFilterService implements WebLogFilterService {
private final Logger logger = LoggerFactory.getLogger(ChainingWebLogFilterService.class);
private final List<WebLogFilter> filters;
public ChainingWebLogFilterService(final List<WebLogFilter> validators) {
this.filters = ImmutableList.copyOf(validators);
}
@Override | public FilterResult isFiltered(LogMessage logMessage) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/parser/RegexLogLineParser.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage; | package net.seleucus.wsp.server.request.parser;
public class RegexLogLineParser implements LogLineParser {
private final Pattern pattern;
public RegexLogLineParser(final String regex){
this.pattern = Pattern.compile(regex);
}
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
// Path: src/main/java/net/seleucus/wsp/server/request/parser/RegexLogLineParser.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
package net.seleucus.wsp.server.request.parser;
public class RegexLogLineParser implements LogLineParser {
private final Pattern pattern;
public RegexLogLineParser(final String regex){
this.pattern = Pattern.compile(regex);
}
@Override | public LogMessage parse(String line) throws LogParseException { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/parser/RegexLogLineParser.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage; | package net.seleucus.wsp.server.request.parser;
public class RegexLogLineParser implements LogLineParser {
private final Pattern pattern;
public RegexLogLineParser(final String regex){
this.pattern = Pattern.compile(regex);
}
@Override
public LogMessage parse(String line) throws LogParseException {
final Matcher matcher = pattern.matcher(line);
if(!matcher.matches()){
throw new LogParseException("Log message does not match the expected regex pattern");
}
//TODO: Extract the log message attributes from the string using regex named groups | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
// Path: src/main/java/net/seleucus/wsp/server/request/parser/RegexLogLineParser.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
package net.seleucus.wsp.server.request.parser;
public class RegexLogLineParser implements LogLineParser {
private final Pattern pattern;
public RegexLogLineParser(final String regex){
this.pattern = Pattern.compile(regex);
}
@Override
public LogMessage parse(String line) throws LogParseException {
final Matcher matcher = pattern.matcher(line);
if(!matcher.matches()){
throw new LogParseException("Log message does not match the expected regex pattern");
}
//TODO: Extract the log message attributes from the string using regex named groups | return createLogMessage().build(); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/WSServerTest.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
| import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before; | package net.seleucus.wsp.server;
public class WSServerTest {
private ByteArrayOutputStream outContent; // = new ByteArrayOutputStream();
private ByteArrayOutputStream errContent; // = new ByteArrayOutputStream();
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
outContent = new ByteArrayOutputStream();
errContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
| // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
// Path: src/test/java/net/seleucus/wsp/server/WSServerTest.java
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
package net.seleucus.wsp.server;
public class WSServerTest {
private ByteArrayOutputStream outContent; // = new ByteArrayOutputStream();
private ByteArrayOutputStream errContent; // = new ByteArrayOutputStream();
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
outContent = new ByteArrayOutputStream();
errContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
| wsServer = new WSServer(new WebSpa(WSConsole.getWsConsole())); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/WSServerTest.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
| import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before; | package net.seleucus.wsp.server;
public class WSServerTest {
private ByteArrayOutputStream outContent; // = new ByteArrayOutputStream();
private ByteArrayOutputStream errContent; // = new ByteArrayOutputStream();
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
outContent = new ByteArrayOutputStream();
errContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
| // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
// Path: src/test/java/net/seleucus/wsp/server/WSServerTest.java
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
package net.seleucus.wsp.server;
public class WSServerTest {
private ByteArrayOutputStream outContent; // = new ByteArrayOutputStream();
private ByteArrayOutputStream errContent; // = new ByteArrayOutputStream();
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
outContent = new ByteArrayOutputStream();
errContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
| wsServer = new WSServer(new WebSpa(WSConsole.getWsConsole())); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/crypto/fwknop/MessageBuilder.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import static net.seleucus.wsp.crypto.fwknop.fields.DigestType.SHA256;
import static net.seleucus.wsp.crypto.fwknop.fields.MessageType.AccessMessage; | package net.seleucus.wsp.crypto.fwknop;
public class MessageBuilder {
private long randomValue;
private String username;
private long timestamp;
private String version = "2.0.2"; | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/MessageBuilder.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import static net.seleucus.wsp.crypto.fwknop.fields.DigestType.SHA256;
import static net.seleucus.wsp.crypto.fwknop.fields.MessageType.AccessMessage;
package net.seleucus.wsp.crypto.fwknop;
public class MessageBuilder {
private long randomValue;
private String username;
private long timestamp;
private String version = "2.0.2"; | private MessageType messageType = AccessMessage; |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/crypto/fwknop/MessageBuilder.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import static net.seleucus.wsp.crypto.fwknop.fields.DigestType.SHA256;
import static net.seleucus.wsp.crypto.fwknop.fields.MessageType.AccessMessage; | package net.seleucus.wsp.crypto.fwknop;
public class MessageBuilder {
private long randomValue;
private String username;
private long timestamp;
private String version = "2.0.2";
private MessageType messageType = AccessMessage;
private String payload; | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/MessageBuilder.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import static net.seleucus.wsp.crypto.fwknop.fields.DigestType.SHA256;
import static net.seleucus.wsp.crypto.fwknop.fields.MessageType.AccessMessage;
package net.seleucus.wsp.crypto.fwknop;
public class MessageBuilder {
private long randomValue;
private String username;
private long timestamp;
private String version = "2.0.2";
private MessageType messageType = AccessMessage;
private String payload; | private DigestType digestType = SHA256; |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/request/filter/filters/Base64EncodedUrlWebLogFilterTest.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
| import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.fest.assertions.api.Assertions.assertThat; | package net.seleucus.wsp.server.request.filter.filters;
public class Base64EncodedUrlWebLogFilterTest {
private final Base64EncodedUrlWebLogFilter filter = new Base64EncodedUrlWebLogFilter();
@Test
public void shouldAcceptBase64Uri() throws Exception { | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
// Path: src/test/java/net/seleucus/wsp/server/request/filter/filters/Base64EncodedUrlWebLogFilterTest.java
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.fest.assertions.api.Assertions.assertThat;
package net.seleucus.wsp.server.request.filter.filters;
public class Base64EncodedUrlWebLogFilterTest {
private final Base64EncodedUrlWebLogFilter filter = new Base64EncodedUrlWebLogFilter();
@Test
public void shouldAcceptBase64Uri() throws Exception { | assertThat(filter.parse(createLogMessage().withRequestUri("/TWFuIGlz").build())).isEqualTo(ACCEPT); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/db/WSPassPhrases.java | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaEncoder.java
// public class WebSpaEncoder {
//
// private CharSequence passPhrase;
// private int actionNumber;
//
// public WebSpaEncoder(CharSequence passPhrase, int actionNumber) {
// this.passPhrase = passPhrase;
// this.actionNumber = actionNumber;
// }
//
// public String getKnock() {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// byte[] actionKnockBytes = ActionNumberCrypto.getHashedActionNumberNow(passPhrase, actionNumber);
//
// byte[] allBytes = ArrayUtils.addAll(passKnockBytes, actionKnockBytes);
//
// return Base64.encodeBase64URLSafeString(allBytes);
// }
//
// public static String encode(CharSequence passPhrase) {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// return Base64.encodeBase64URLSafeString(passKnockBytes);
// }
//
// public static boolean matches(CharSequence rawPassword, String webSpaRequest) {
//
// if(webSpaRequest.length() != 100) {
//
// return false;
//
// } else {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] passBytes = ArrayUtils.subarray(webSpaBytes, 0, 51);
// byte randomByte = webSpaBytes[0];
//
// byte[] expectedBytes = PassPhraseCrypto.getHashedPassPhraseNowWithSalt(rawPassword, randomByte);
//
// return WebSpaUtils.equals(passBytes, expectedBytes);
// }
// }
//
// public static int getActionNumber(CharSequence rawPassword, String webSpaRequest) {
//
// int returnAction = -1;
//
// if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] actionBytes = ArrayUtils.subarray(webSpaBytes, 51, 75);
// byte[] actionSalt = ArrayUtils.subarray(actionBytes, 0, 4);
//
// for(int count = 0; count <= 9; count++) {
//
// byte[] calculatedActionBytes =
// ActionNumberCrypto.getHashedActionNumberNowWithSalt(rawPassword, count, actionSalt);
//
// if(WebSpaUtils.equals(calculatedActionBytes, actionBytes)) {
// returnAction = count;
// break;
// }
//
// } // for loop
// }
//
// return returnAction;
// }
//
// }
| import java.nio.CharBuffer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.seleucus.wsp.crypto.WebSpaEncoder; |
ps.executeUpdate();
} catch (SQLException ex) {
LOGGER.error("Toggle User Activation - A Database exception has occured: {}.", ex.getMessage());
}
} // ppID > 0
return success;
}
public synchronized int getPPIDFromRequest(final String webSpaRequest) {
int output = -1;
final String sqlPassPhrases = "SELECT PASSPHRASE, PPID FROM PASSPHRASES;";
try {
Statement stmt = wsConnection.createStatement();
ResultSet rs = stmt.executeQuery(sqlPassPhrases);
while (rs.next()) {
char[] dbPassPhraseArray = rs.getString(1).toCharArray();
final int dbPPID = rs.getInt(2);
CharSequence rawPassword = CharBuffer.wrap(dbPassPhraseArray);
| // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaEncoder.java
// public class WebSpaEncoder {
//
// private CharSequence passPhrase;
// private int actionNumber;
//
// public WebSpaEncoder(CharSequence passPhrase, int actionNumber) {
// this.passPhrase = passPhrase;
// this.actionNumber = actionNumber;
// }
//
// public String getKnock() {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// byte[] actionKnockBytes = ActionNumberCrypto.getHashedActionNumberNow(passPhrase, actionNumber);
//
// byte[] allBytes = ArrayUtils.addAll(passKnockBytes, actionKnockBytes);
//
// return Base64.encodeBase64URLSafeString(allBytes);
// }
//
// public static String encode(CharSequence passPhrase) {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// return Base64.encodeBase64URLSafeString(passKnockBytes);
// }
//
// public static boolean matches(CharSequence rawPassword, String webSpaRequest) {
//
// if(webSpaRequest.length() != 100) {
//
// return false;
//
// } else {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] passBytes = ArrayUtils.subarray(webSpaBytes, 0, 51);
// byte randomByte = webSpaBytes[0];
//
// byte[] expectedBytes = PassPhraseCrypto.getHashedPassPhraseNowWithSalt(rawPassword, randomByte);
//
// return WebSpaUtils.equals(passBytes, expectedBytes);
// }
// }
//
// public static int getActionNumber(CharSequence rawPassword, String webSpaRequest) {
//
// int returnAction = -1;
//
// if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] actionBytes = ArrayUtils.subarray(webSpaBytes, 51, 75);
// byte[] actionSalt = ArrayUtils.subarray(actionBytes, 0, 4);
//
// for(int count = 0; count <= 9; count++) {
//
// byte[] calculatedActionBytes =
// ActionNumberCrypto.getHashedActionNumberNowWithSalt(rawPassword, count, actionSalt);
//
// if(WebSpaUtils.equals(calculatedActionBytes, actionBytes)) {
// returnAction = count;
// break;
// }
//
// } // for loop
// }
//
// return returnAction;
// }
//
// }
// Path: src/main/java/net/seleucus/wsp/db/WSPassPhrases.java
import java.nio.CharBuffer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.seleucus.wsp.crypto.WebSpaEncoder;
ps.executeUpdate();
} catch (SQLException ex) {
LOGGER.error("Toggle User Activation - A Database exception has occured: {}.", ex.getMessage());
}
} // ppID > 0
return success;
}
public synchronized int getPPIDFromRequest(final String webSpaRequest) {
int output = -1;
final String sqlPassPhrases = "SELECT PASSPHRASE, PPID FROM PASSPHRASES;";
try {
Statement stmt = wsConnection.createStatement();
ResultSet rs = stmt.executeQuery(sqlPassPhrases);
while (rs.next()) {
char[] dbPassPhraseArray = rs.getString(1).toCharArray();
final int dbPPID = rs.getInt(2);
CharSequence rawPassword = CharBuffer.wrap(dbPassPhraseArray);
| if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/db/WSActionsAvailable.java | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaEncoder.java
// public class WebSpaEncoder {
//
// private CharSequence passPhrase;
// private int actionNumber;
//
// public WebSpaEncoder(CharSequence passPhrase, int actionNumber) {
// this.passPhrase = passPhrase;
// this.actionNumber = actionNumber;
// }
//
// public String getKnock() {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// byte[] actionKnockBytes = ActionNumberCrypto.getHashedActionNumberNow(passPhrase, actionNumber);
//
// byte[] allBytes = ArrayUtils.addAll(passKnockBytes, actionKnockBytes);
//
// return Base64.encodeBase64URLSafeString(allBytes);
// }
//
// public static String encode(CharSequence passPhrase) {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// return Base64.encodeBase64URLSafeString(passKnockBytes);
// }
//
// public static boolean matches(CharSequence rawPassword, String webSpaRequest) {
//
// if(webSpaRequest.length() != 100) {
//
// return false;
//
// } else {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] passBytes = ArrayUtils.subarray(webSpaBytes, 0, 51);
// byte randomByte = webSpaBytes[0];
//
// byte[] expectedBytes = PassPhraseCrypto.getHashedPassPhraseNowWithSalt(rawPassword, randomByte);
//
// return WebSpaUtils.equals(passBytes, expectedBytes);
// }
// }
//
// public static int getActionNumber(CharSequence rawPassword, String webSpaRequest) {
//
// int returnAction = -1;
//
// if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] actionBytes = ArrayUtils.subarray(webSpaBytes, 51, 75);
// byte[] actionSalt = ArrayUtils.subarray(actionBytes, 0, 4);
//
// for(int count = 0; count <= 9; count++) {
//
// byte[] calculatedActionBytes =
// ActionNumberCrypto.getHashedActionNumberNowWithSalt(rawPassword, count, actionSalt);
//
// if(WebSpaUtils.equals(calculatedActionBytes, actionBytes)) {
// returnAction = count;
// break;
// }
//
// } // for loop
// }
//
// return returnAction;
// }
//
// }
| import java.nio.CharBuffer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.seleucus.wsp.crypto.WebSpaEncoder; | preStatement.setString(3, osCommand);
preStatement.executeUpdate();
preStatement.close();
} catch (SQLException ex) {
LOGGER.error("Add Add Action - A Database exception has occured: {}.", ex.getMessage());
}
}
public synchronized int getActionNumberFromRequest(final int ppID, final String webSpaRequest) {
int actionNumber = -1;
if(ppID > 0) {
String sqlActivationLookup = "SELECT PASSPHRASE FROM PASSPHRASES WHERE PPID = ? ;";
try {
PreparedStatement psPassPhrase = wsConnection.prepareStatement(sqlActivationLookup);
psPassPhrase.setInt(1, ppID);
ResultSet rs = psPassPhrase.executeQuery();
if (rs.next()) {
char[] dbPassPhraseArray = rs.getString(1).toCharArray();
CharSequence rawPassword = CharBuffer.wrap(dbPassPhraseArray);
| // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaEncoder.java
// public class WebSpaEncoder {
//
// private CharSequence passPhrase;
// private int actionNumber;
//
// public WebSpaEncoder(CharSequence passPhrase, int actionNumber) {
// this.passPhrase = passPhrase;
// this.actionNumber = actionNumber;
// }
//
// public String getKnock() {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// byte[] actionKnockBytes = ActionNumberCrypto.getHashedActionNumberNow(passPhrase, actionNumber);
//
// byte[] allBytes = ArrayUtils.addAll(passKnockBytes, actionKnockBytes);
//
// return Base64.encodeBase64URLSafeString(allBytes);
// }
//
// public static String encode(CharSequence passPhrase) {
// byte[] passKnockBytes = PassPhraseCrypto.getHashedPassPhraseNow(passPhrase);
// return Base64.encodeBase64URLSafeString(passKnockBytes);
// }
//
// public static boolean matches(CharSequence rawPassword, String webSpaRequest) {
//
// if(webSpaRequest.length() != 100) {
//
// return false;
//
// } else {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] passBytes = ArrayUtils.subarray(webSpaBytes, 0, 51);
// byte randomByte = webSpaBytes[0];
//
// byte[] expectedBytes = PassPhraseCrypto.getHashedPassPhraseNowWithSalt(rawPassword, randomByte);
//
// return WebSpaUtils.equals(passBytes, expectedBytes);
// }
// }
//
// public static int getActionNumber(CharSequence rawPassword, String webSpaRequest) {
//
// int returnAction = -1;
//
// if(WebSpaEncoder.matches(rawPassword, webSpaRequest)) {
//
// byte[] webSpaBytes = Base64.decodeBase64(webSpaRequest);
// byte[] actionBytes = ArrayUtils.subarray(webSpaBytes, 51, 75);
// byte[] actionSalt = ArrayUtils.subarray(actionBytes, 0, 4);
//
// for(int count = 0; count <= 9; count++) {
//
// byte[] calculatedActionBytes =
// ActionNumberCrypto.getHashedActionNumberNowWithSalt(rawPassword, count, actionSalt);
//
// if(WebSpaUtils.equals(calculatedActionBytes, actionBytes)) {
// returnAction = count;
// break;
// }
//
// } // for loop
// }
//
// return returnAction;
// }
//
// }
// Path: src/main/java/net/seleucus/wsp/db/WSActionsAvailable.java
import java.nio.CharBuffer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.seleucus.wsp.crypto.WebSpaEncoder;
preStatement.setString(3, osCommand);
preStatement.executeUpdate();
preStatement.close();
} catch (SQLException ex) {
LOGGER.error("Add Add Action - A Database exception has occured: {}.", ex.getMessage());
}
}
public synchronized int getActionNumberFromRequest(final int ppID, final String webSpaRequest) {
int actionNumber = -1;
if(ppID > 0) {
String sqlActivationLookup = "SELECT PASSPHRASE FROM PASSPHRASES WHERE PPID = ? ;";
try {
PreparedStatement psPassPhrase = wsConnection.prepareStatement(sqlActivationLookup);
psPassPhrase.setInt(1, ppID);
ResultSet rs = psPassPhrase.executeQuery();
if (rs.next()) {
char[] dbPassPhraseArray = rs.getString(1).toCharArray();
CharSequence rawPassword = CharBuffer.wrap(dbPassPhraseArray);
| actionNumber = WebSpaEncoder.getActionNumber(rawPassword, webSpaRequest); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataRow.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType; | package net.seleucus.wsp.crypto.fwknop;
public class TestDataRow {
private byte[] encryptionKey;
private byte[] signatureKey; | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
// Path: src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataRow.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
package net.seleucus.wsp.crypto.fwknop;
public class TestDataRow {
private byte[] encryptionKey;
private byte[] signatureKey; | private DigestType digestType; |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataRow.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType; | package net.seleucus.wsp.crypto.fwknop;
public class TestDataRow {
private byte[] encryptionKey;
private byte[] signatureKey;
private DigestType digestType; | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
// Path: src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataRow.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
package net.seleucus.wsp.crypto.fwknop;
public class TestDataRow {
private byte[] encryptionKey;
private byte[] signatureKey;
private DigestType digestType; | private HmacType hmacType; |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataRow.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType; | package net.seleucus.wsp.crypto.fwknop;
public class TestDataRow {
private byte[] encryptionKey;
private byte[] signatureKey;
private DigestType digestType;
private HmacType hmacType;
private long randomValue;
private String userName;
private long timestamp;
private String version; | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
// Path: src/test/java/net/seleucus/wsp/crypto/fwknop/TestDataRow.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
package net.seleucus.wsp.crypto.fwknop;
public class TestDataRow {
private byte[] encryptionKey;
private byte[] signatureKey;
private DigestType digestType;
private HmacType hmacType;
private long randomValue;
private String userName;
private long timestamp;
private String version; | private MessageType messageType; |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilterTest.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.apache.commons.lang3.RandomStringUtils.randomAscii;
import static org.fest.assertions.api.Assertions.assertThat; | package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilterTest {
private static final int MIN_ALLOWED_LENGTH = 10;
private static final int MAX_ALLOWED_LENGTH = 20;
| // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
// Path: src/test/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilterTest.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.apache.commons.lang3.RandomStringUtils.randomAscii;
import static org.fest.assertions.api.Assertions.assertThat;
package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilterTest {
private static final int MIN_ALLOWED_LENGTH = 10;
private static final int MAX_ALLOWED_LENGTH = 20;
| private final WebLogFilter filter = new UriLengthWebLogFilter(MIN_ALLOWED_LENGTH, MAX_ALLOWED_LENGTH); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilterTest.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.apache.commons.lang3.RandomStringUtils.randomAscii;
import static org.fest.assertions.api.Assertions.assertThat; | package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilterTest {
private static final int MIN_ALLOWED_LENGTH = 10;
private static final int MAX_ALLOWED_LENGTH = 20;
private final WebLogFilter filter = new UriLengthWebLogFilter(MIN_ALLOWED_LENGTH, MAX_ALLOWED_LENGTH);
@Test
public void shouldReturnAcceptWhereLengthIsBetweenMinAndMax() throws Exception { | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
// Path: src/test/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilterTest.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.apache.commons.lang3.RandomStringUtils.randomAscii;
import static org.fest.assertions.api.Assertions.assertThat;
package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilterTest {
private static final int MIN_ALLOWED_LENGTH = 10;
private static final int MAX_ALLOWED_LENGTH = 20;
private final WebLogFilter filter = new UriLengthWebLogFilter(MIN_ALLOWED_LENGTH, MAX_ALLOWED_LENGTH);
@Test
public void shouldReturnAcceptWhereLengthIsBetweenMinAndMax() throws Exception { | final LogMessage logMessage = createLogMessage().withRequestUri(randomAscii(MAX_ALLOWED_LENGTH - 1)).build(); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilterTest.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.apache.commons.lang3.RandomStringUtils.randomAscii;
import static org.fest.assertions.api.Assertions.assertThat; | package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilterTest {
private static final int MIN_ALLOWED_LENGTH = 10;
private static final int MAX_ALLOWED_LENGTH = 20;
private final WebLogFilter filter = new UriLengthWebLogFilter(MIN_ALLOWED_LENGTH, MAX_ALLOWED_LENGTH);
@Test
public void shouldReturnAcceptWhereLengthIsBetweenMinAndMax() throws Exception { | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
// Path: src/test/java/net/seleucus/wsp/server/request/filter/filters/UriLengthWebLogFilterTest.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.junit.Test;
import static net.seleucus.wsp.server.request.domain.LogMessage.LogMessageBuilder.createLogMessage;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.apache.commons.lang3.RandomStringUtils.randomAscii;
import static org.fest.assertions.api.Assertions.assertThat;
package net.seleucus.wsp.server.request.filter.filters;
public class UriLengthWebLogFilterTest {
private static final int MIN_ALLOWED_LENGTH = 10;
private static final int MAX_ALLOWED_LENGTH = 20;
private final WebLogFilter filter = new UriLengthWebLogFilter(MIN_ALLOWED_LENGTH, MAX_ALLOWED_LENGTH);
@Test
public void shouldReturnAcceptWhereLengthIsBetweenMinAndMax() throws Exception { | final LogMessage logMessage = createLogMessage().withRequestUri(randomAscii(MAX_ALLOWED_LENGTH - 1)).build(); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/config/WSConfiguration.java | // Path: src/main/java/net/seleucus/wsp/util/WSConstants.java
// public class WSConstants {
//
// public static final String LOGGING_REGEX_FOR_EACH_REQUEST = "logging-regex-for-each-request";
// public static final String ACCESS_LOG_FILE_LOCATION = "access-log-file-location";
//
// }
| import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import net.seleucus.wsp.util.WSConstants;
import org.apache.commons.io.FileUtils; | package net.seleucus.wsp.config;
public class WSConfiguration {
protected static final String CONFIG_PATH = "webspa-config.properties";
private Properties configProperties;
public WSConfiguration() throws IOException {
// Check if the configuration properties file is present, if not create
// it from the bundled template...
File configFile = new File(CONFIG_PATH);
if (!configFile.exists()) {
URL bundledConfigLocation = ClassLoader
.getSystemResource("config/bundled-webspa-config.properties");
FileUtils.copyURLToFile(bundledConfigLocation, configFile);
}
FileInputStream in = new FileInputStream(configFile);
configProperties = new Properties();
configProperties.load(in);
in.close();
}
public String getAccesLogFileLocation() {
| // Path: src/main/java/net/seleucus/wsp/util/WSConstants.java
// public class WSConstants {
//
// public static final String LOGGING_REGEX_FOR_EACH_REQUEST = "logging-regex-for-each-request";
// public static final String ACCESS_LOG_FILE_LOCATION = "access-log-file-location";
//
// }
// Path: src/main/java/net/seleucus/wsp/config/WSConfiguration.java
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import net.seleucus.wsp.util.WSConstants;
import org.apache.commons.io.FileUtils;
package net.seleucus.wsp.config;
public class WSConfiguration {
protected static final String CONFIG_PATH = "webspa-config.properties";
private Properties configProperties;
public WSConfiguration() throws IOException {
// Check if the configuration properties file is present, if not create
// it from the bundled template...
File configFile = new File(CONFIG_PATH);
if (!configFile.exists()) {
URL bundledConfigLocation = ClassLoader
.getSystemResource("config/bundled-webspa-config.properties");
FileUtils.copyURLToFile(bundledConfigLocation, configFile);
}
FileInputStream in = new FileInputStream(configFile);
configProperties = new Properties();
configProperties.load(in);
in.close();
}
public String getAccesLogFileLocation() {
| return configProperties.getProperty(WSConstants.ACCESS_LOG_FILE_LOCATION); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/WSActionTest.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
| import static org.junit.Assert.*;
import java.io.File;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; | package net.seleucus.wsp.server;
public class WSActionTest {
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
| // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
// Path: src/test/java/net/seleucus/wsp/server/WSActionTest.java
import static org.junit.Assert.*;
import java.io.File;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
package net.seleucus.wsp.server;
public class WSActionTest {
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
| wsServer = new WSServer(new WebSpa(WSConsole.getWsConsole())); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/WSActionTest.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
| import static org.junit.Assert.*;
import java.io.File;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; | package net.seleucus.wsp.server;
public class WSActionTest {
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
| // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
// Path: src/test/java/net/seleucus/wsp/server/WSActionTest.java
import static org.junit.Assert.*;
import java.io.File;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
package net.seleucus.wsp.server;
public class WSActionTest {
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
| wsServer = new WSServer(new WebSpa(WSConsole.getWsConsole())); |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/filters/Base64EncodedUrlWebLogFilter.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.apache.commons.codec.binary.Base64; | package net.seleucus.wsp.server.request.filter.filters;
public class Base64EncodedUrlWebLogFilter implements WebLogFilter {
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/filters/Base64EncodedUrlWebLogFilter.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.apache.commons.codec.binary.Base64;
package net.seleucus.wsp.server.request.filter.filters;
public class Base64EncodedUrlWebLogFilter implements WebLogFilter {
@Override | public FilterResult parse(LogMessage logMessage) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/filters/Base64EncodedUrlWebLogFilter.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.apache.commons.codec.binary.Base64; | package net.seleucus.wsp.server.request.filter.filters;
public class Base64EncodedUrlWebLogFilter implements WebLogFilter {
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/filters/Base64EncodedUrlWebLogFilter.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import org.apache.commons.codec.binary.Base64;
package net.seleucus.wsp.server.request.filter.filters;
public class Base64EncodedUrlWebLogFilter implements WebLogFilter {
@Override | public FilterResult parse(LogMessage logMessage) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/main/WSGestalt.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
| import net.seleucus.wsp.console.WSConsole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.CharBuffer;
import java.sql.SQLException;
import java.util.Arrays; | package net.seleucus.wsp.main;
public abstract class WSGestalt {
private final static Logger LOGGER = LoggerFactory.getLogger(WSGestalt.class);
private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_BLUE = "\u001B[34m";
private static final String ANSI_PURPLE = "\u001B[35m";
private static final String ANSI_RESET = "\u001B[0m";
| // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
// Path: src/main/java/net/seleucus/wsp/main/WSGestalt.java
import net.seleucus.wsp.console.WSConsole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.CharBuffer;
import java.sql.SQLException;
import java.util.Arrays;
package net.seleucus.wsp.main;
public abstract class WSGestalt {
private final static Logger LOGGER = LoggerFactory.getLogger(WSGestalt.class);
private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_BLUE = "\u001B[34m";
private static final String ANSI_PURPLE = "\u001B[35m";
private static final String ANSI_RESET = "\u001B[0m";
| protected final WSConsole myConsole; |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/WSServerConsoleTest.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
| import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; | package net.seleucus.wsp.server;
public class WSServerConsoleTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
| // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
// Path: src/test/java/net/seleucus/wsp/server/WSServerConsoleTest.java
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
package net.seleucus.wsp.server;
public class WSServerConsoleTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
| wsServer = new WSServer(new WebSpa(WSConsole.getWsConsole())); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/WSServerConsoleTest.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
| import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; | package net.seleucus.wsp.server;
public class WSServerConsoleTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
| // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/main/WebSpa.java
// public class WebSpa {
//
// private final static Logger LOGGER = LoggerFactory.getLogger(WebSpa.class);
//
// private WSConsole myConsole;
//
// public WebSpa(final WSConsole myConsole) {
// this.myConsole = myConsole;
// }
//
// public WSConsole getConsole() {
// return myConsole;
// }
//
// public CommandLineArgument processParameters(final String[] args) {
// if(args.length == 0){
// return SHOW_HELP;
// }
//
// final CommandLineArgument mode = CommandLineArgument.getByName(args[0]);
// return mode != null ? mode : SHOW_HELP;
// }
//
// public static void main(String[] args) throws Exception {
// if(! WSUtil.hasMinJreRequirements(1, 6)) {
// LOGGER.error("!!! Minimum JRE requirements are 1.6 !!!");
// System.exit(1);
// }
//
// WSGestalt wsGestalt;
// final WebSpa webSpa = new WebSpa(WSConsole.getWsConsole());
// final CommandLineArgument argument = webSpa.processParameters(args);
//
// switch (argument) {
// case SHOW_HELP:
// LOGGER.info("Invalid Parameter Specified - Use \"java -jar webspa-{}{}.jar -help\" for More Options", WSVersion.getMajor(), WSVersion.getMinor() );
// wsGestalt = new WSHelper(webSpa);
// break;
// case CLIENT_MODE:
// LOGGER.info("Welcome - Running the WebSpa Client");
// wsGestalt = new WSClient(webSpa);
// break;
// case SERVER_MODE:
// LOGGER.info("Welcome - Running the WebSpa Server");
// wsGestalt = new WSServer(webSpa);
// break;
// case SHOW_VERSION:
// wsGestalt = new WSVersion(webSpa);
// break;
// case START:
// LOGGER.info("No Action - A Future Way to Start the WebSpa Server");
// wsGestalt = new WSDaemonStart(webSpa);
// break;
// case STOP:
// LOGGER.info("No Action - A Future Way to Stop the WebSpa Server");
// wsGestalt = new WSDaemonStop(webSpa);
// break;
// case SHOW_STATUS:
// LOGGER.info("No Action - A Future Way to Query the Status of the WebSpa Server");
// wsGestalt = new WSDaemonStatus(webSpa);
// break;
// default:
// wsGestalt = new WSHelper(webSpa);
// break;
// }
// wsGestalt.runConsole();
// wsGestalt.exitConsole();
// }
// }
// Path: src/test/java/net/seleucus/wsp/server/WSServerConsoleTest.java
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import net.seleucus.wsp.console.WSConsole;
import net.seleucus.wsp.main.WebSpa;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
package net.seleucus.wsp.server;
public class WSServerConsoleTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private WSServer wsServer;
@Before
public void setUpStreams() throws Exception {
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
| wsServer = new WSServer(new WebSpa(WSConsole.getWsConsole())); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/WSEncoderTest.java | // Path: src/main/java/net/seleucus/wsp/crypto/WSEncoder.java
// public class WSEncoder {
//
// public byte[] decode(String base64String) throws DecoderException {
// return Base64.decodeBase64(base64String);
// }
//
// public String encode(byte[] binaryData) {
// return Base64.encodeBase64URLSafeString(binaryData);
// }
//
// }
| import static org.junit.Assert.*;
import net.seleucus.wsp.crypto.WSEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test; | package net.seleucus.wsp.crypto;
public class WSEncoderTest {
@Test
public final void shouldDecodeToTheSameEncodedString() throws DecoderException { | // Path: src/main/java/net/seleucus/wsp/crypto/WSEncoder.java
// public class WSEncoder {
//
// public byte[] decode(String base64String) throws DecoderException {
// return Base64.decodeBase64(base64String);
// }
//
// public String encode(byte[] binaryData) {
// return Base64.encodeBase64URLSafeString(binaryData);
// }
//
// }
// Path: src/test/java/net/seleucus/wsp/crypto/WSEncoderTest.java
import static org.junit.Assert.*;
import net.seleucus.wsp.crypto.WSEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;
package net.seleucus.wsp.crypto;
public class WSEncoderTest {
@Test
public final void shouldDecodeToTheSameEncodedString() throws DecoderException { | WSEncoder myEncoder = new WSEncoder(); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/server/request/filter/ChainingWebLogValidationServiceTest.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
| import com.google.common.collect.ImmutableList;
import net.seleucus.wsp.server.request.domain.LogMessage;
import org.junit.Test;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; | package net.seleucus.wsp.server.request.filter;
public class ChainingWebLogValidationServiceTest {
@Test
public void shouldAcceptIfSingleFilterReturnsAccept() throws Exception {
assertThat(createService(createFilter(ACCEPT))).isEqualTo(ACCEPT);
}
@Test
public void shouldDropIfSingleFilterReturnsAccept() throws Exception {
assertThat(createService(createFilter(DROP))).isEqualTo(DROP);
}
@Test
public void shouldAcceptIfMultipleAndAllFiltersReturnAccept(){
assertThat(createService(createFilter(ACCEPT), createFilter(ACCEPT))).isEqualTo(ACCEPT);
}
@Test
public void shouldDropIfMultipleAndAllFiltersReturnAccept(){
assertThat(createService(createFilter(DROP), createFilter(DROP))).isEqualTo(DROP);
}
@Test
public void shouldDropIfAnyFilterReturnsDrop(){
assertThat(createService(createFilter(ACCEPT), createFilter(DROP))).isEqualTo(DROP);
assertThat(createService(createFilter(DROP), createFilter(ACCEPT))).isEqualTo(DROP);
}
private FilterResult createService(WebLogFilter... filters){
final WebLogFilterService filterService = new ChainingWebLogFilterService(ImmutableList.copyOf(filters)); | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
// Path: src/test/java/net/seleucus/wsp/server/request/filter/ChainingWebLogValidationServiceTest.java
import com.google.common.collect.ImmutableList;
import net.seleucus.wsp.server.request.domain.LogMessage;
import org.junit.Test;
import static net.seleucus.wsp.server.request.filter.FilterResult.ACCEPT;
import static net.seleucus.wsp.server.request.filter.FilterResult.DROP;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package net.seleucus.wsp.server.request.filter;
public class ChainingWebLogValidationServiceTest {
@Test
public void shouldAcceptIfSingleFilterReturnsAccept() throws Exception {
assertThat(createService(createFilter(ACCEPT))).isEqualTo(ACCEPT);
}
@Test
public void shouldDropIfSingleFilterReturnsAccept() throws Exception {
assertThat(createService(createFilter(DROP))).isEqualTo(DROP);
}
@Test
public void shouldAcceptIfMultipleAndAllFiltersReturnAccept(){
assertThat(createService(createFilter(ACCEPT), createFilter(ACCEPT))).isEqualTo(ACCEPT);
}
@Test
public void shouldDropIfMultipleAndAllFiltersReturnAccept(){
assertThat(createService(createFilter(DROP), createFilter(DROP))).isEqualTo(DROP);
}
@Test
public void shouldDropIfAnyFilterReturnsDrop(){
assertThat(createService(createFilter(ACCEPT), createFilter(DROP))).isEqualTo(DROP);
assertThat(createService(createFilter(DROP), createFilter(ACCEPT))).isEqualTo(DROP);
}
private FilterResult createService(WebLogFilter... filters){
final WebLogFilterService filterService = new ChainingWebLogFilterService(ImmutableList.copyOf(filters)); | return filterService.isFiltered(mock(LogMessage.class)); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoServiceTest.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/MessageBuilder.java
// public static MessageBuilder createMessage(){
// return new MessageBuilder();
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;
import java.security.SecureRandom;
import static java.lang.Math.abs;
import static net.seleucus.wsp.crypto.fwknop.MessageBuilder.createMessage;
import static net.seleucus.wsp.crypto.fwknop.fields.DigestType.SHA256;
import static net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode.CBC;
import static net.seleucus.wsp.crypto.fwknop.fields.EncryptionType.AES;
import static net.seleucus.wsp.crypto.fwknop.fields.HmacType.*;
import static net.seleucus.wsp.crypto.fwknop.fields.MessageType.AccessMessage;
import static org.junit.Assert.*; |
@Test
public void shouldVerifyThrowExceptionForToShortMessage() {
String auth_key_encoded = "4c7660e21cf971c70ec8beb622fa966d3ab03ab03a301a2162afa930377737582aae061d0c61590ba2b0453e914d9385cc42250ae6e2cbeca73c8979676da82b";
byte[] auth_key = decodeFromHexString(auth_key_encoded);
String message = "YWFhYWFhYWFhYWFhYWFhYW";
try {
service.verify(auth_key, message, HmacMD5);
}
catch (IllegalArgumentException e) {
// this should be thrown
}
catch (Exception e) {
fail ("Unexpected exception: " + e.getMessage());
}
}
@Test
public void shouldSignAndVerifyWithHmacTypes() {
final byte[] keyBytes = new byte[64];
final int msgLen = 1 + (abs(sr.nextInt()) % 512);
final byte[] msg = new byte[msgLen];
sr.nextBytes(keyBytes);
sr.nextBytes(msg);
final String message = Base64.encodeBase64String(msg);
| // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/MessageBuilder.java
// public static MessageBuilder createMessage(){
// return new MessageBuilder();
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
// Path: src/test/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoServiceTest.java
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;
import java.security.SecureRandom;
import static java.lang.Math.abs;
import static net.seleucus.wsp.crypto.fwknop.MessageBuilder.createMessage;
import static net.seleucus.wsp.crypto.fwknop.fields.DigestType.SHA256;
import static net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode.CBC;
import static net.seleucus.wsp.crypto.fwknop.fields.EncryptionType.AES;
import static net.seleucus.wsp.crypto.fwknop.fields.HmacType.*;
import static net.seleucus.wsp.crypto.fwknop.fields.MessageType.AccessMessage;
import static org.junit.Assert.*;
@Test
public void shouldVerifyThrowExceptionForToShortMessage() {
String auth_key_encoded = "4c7660e21cf971c70ec8beb622fa966d3ab03ab03a301a2162afa930377737582aae061d0c61590ba2b0453e914d9385cc42250ae6e2cbeca73c8979676da82b";
byte[] auth_key = decodeFromHexString(auth_key_encoded);
String message = "YWFhYWFhYWFhYWFhYWFhYW";
try {
service.verify(auth_key, message, HmacMD5);
}
catch (IllegalArgumentException e) {
// this should be thrown
}
catch (Exception e) {
fail ("Unexpected exception: " + e.getMessage());
}
}
@Test
public void shouldSignAndVerifyWithHmacTypes() {
final byte[] keyBytes = new byte[64];
final int msgLen = 1 + (abs(sr.nextInt()) % 512);
final byte[] msg = new byte[msgLen];
sr.nextBytes(keyBytes);
sr.nextBytes(msg);
final String message = Base64.encodeBase64String(msg);
| for(final HmacType hmacType : HmacType.values()){ |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoServiceTest.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/MessageBuilder.java
// public static MessageBuilder createMessage(){
// return new MessageBuilder();
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
| import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;
import java.security.SecureRandom;
import static java.lang.Math.abs;
import static net.seleucus.wsp.crypto.fwknop.MessageBuilder.createMessage;
import static net.seleucus.wsp.crypto.fwknop.fields.DigestType.SHA256;
import static net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode.CBC;
import static net.seleucus.wsp.crypto.fwknop.fields.EncryptionType.AES;
import static net.seleucus.wsp.crypto.fwknop.fields.HmacType.*;
import static net.seleucus.wsp.crypto.fwknop.fields.MessageType.AccessMessage;
import static org.junit.Assert.*; | *
* SPA Field Values:
* =================
*
* Random Value: 1662754693713426
* Username: imberda
* Timestamp: 1424728557
* FKO Version: 2.0.2
* Message Type: 1 (Access msg)
* Message String: 1.1.1.1,tcp/80
* Nat Access: <NULL>
* Server Auth: <NULL>
* Client Timeout: 0
* Digest Type: 3 (SHA256)
* HMAC Type: 3 (SHA256)
* Encryption Type: 1 (Rijndael)
* Encryption Mode: 2 (CBC)
* Encoded Data: 1662754693713426:aW1iZXJkYQ:1424728557:2.0.2:1:MS4xLjEuMSx0Y3AvODA
* SPA Data Digest: jEscqvxrSt7+Lb2cQ+ICwgX4mhuSp86P8XikxSbga1s
* HMAC: Kn75C+V+O0xu3nzVvvdteuHk0zBptmFep8LQD/JgfWo
* Final SPA Data: 9sPsHAzpiUCLultUmkjizcRSb0eIkvlXLq9noQ4WbXAT3HlZhWLHoKGAM+TOOtIMxRJ6sOSAlzhx6wNgCQiZ3msYcNslJC0F9xxVYVhw8kNon4uuzXoZyCBb3g9m+nZVVyRyy3f0UO+eljC9WRHTsRs5m6Qlryzec
*
*
* @throws Exception
*/
@Test
public void shouldEncryptAndDecrypt() throws Exception {
final byte[] encryptKey = "ENCRYPTION_KEY".getBytes();
| // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/MessageBuilder.java
// public static MessageBuilder createMessage(){
// return new MessageBuilder();
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
// Path: src/test/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoServiceTest.java
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.junit.Test;
import java.security.SecureRandom;
import static java.lang.Math.abs;
import static net.seleucus.wsp.crypto.fwknop.MessageBuilder.createMessage;
import static net.seleucus.wsp.crypto.fwknop.fields.DigestType.SHA256;
import static net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode.CBC;
import static net.seleucus.wsp.crypto.fwknop.fields.EncryptionType.AES;
import static net.seleucus.wsp.crypto.fwknop.fields.HmacType.*;
import static net.seleucus.wsp.crypto.fwknop.fields.MessageType.AccessMessage;
import static org.junit.Assert.*;
*
* SPA Field Values:
* =================
*
* Random Value: 1662754693713426
* Username: imberda
* Timestamp: 1424728557
* FKO Version: 2.0.2
* Message Type: 1 (Access msg)
* Message String: 1.1.1.1,tcp/80
* Nat Access: <NULL>
* Server Auth: <NULL>
* Client Timeout: 0
* Digest Type: 3 (SHA256)
* HMAC Type: 3 (SHA256)
* Encryption Type: 1 (Rijndael)
* Encryption Mode: 2 (CBC)
* Encoded Data: 1662754693713426:aW1iZXJkYQ:1424728557:2.0.2:1:MS4xLjEuMSx0Y3AvODA
* SPA Data Digest: jEscqvxrSt7+Lb2cQ+ICwgX4mhuSp86P8XikxSbga1s
* HMAC: Kn75C+V+O0xu3nzVvvdteuHk0zBptmFep8LQD/JgfWo
* Final SPA Data: 9sPsHAzpiUCLultUmkjizcRSb0eIkvlXLq9noQ4WbXAT3HlZhWLHoKGAM+TOOtIMxRJ6sOSAlzhx6wNgCQiZ3msYcNslJC0F9xxVYVhw8kNon4uuzXoZyCBb3g9m+nZVVyRyy3f0UO+eljC9WRHTsRs5m6Qlryzec
*
*
* @throws Exception
*/
@Test
public void shouldEncryptAndDecrypt() throws Exception {
final byte[] encryptKey = "ENCRYPTION_KEY".getBytes();
| final Message message = createMessage() |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/crypto/fwknop/Message.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopBase64.java
// public static String encode(byte[] input){
// return StringUtils.remove(Base64.encodeBase64String(input), CHAR_TO_REMOVE);
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static java.util.Objects.requireNonNull;
import static net.seleucus.wsp.crypto.fwknop.FwknopBase64.encode;
import static org.apache.commons.codec.Charsets.UTF_8; | package net.seleucus.wsp.crypto.fwknop;
public class Message {
public static final char FIELD_DELIMITER = ':';
private final long randomValue;
private final String username;
private final long timestamp;
private final String version; | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopBase64.java
// public static String encode(byte[] input){
// return StringUtils.remove(Base64.encodeBase64String(input), CHAR_TO_REMOVE);
// }
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/Message.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static java.util.Objects.requireNonNull;
import static net.seleucus.wsp.crypto.fwknop.FwknopBase64.encode;
import static org.apache.commons.codec.Charsets.UTF_8;
package net.seleucus.wsp.crypto.fwknop;
public class Message {
public static final char FIELD_DELIMITER = ':';
private final long randomValue;
private final String username;
private final long timestamp;
private final String version; | private final MessageType messageType; |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/crypto/fwknop/Message.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopBase64.java
// public static String encode(byte[] input){
// return StringUtils.remove(Base64.encodeBase64String(input), CHAR_TO_REMOVE);
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static java.util.Objects.requireNonNull;
import static net.seleucus.wsp.crypto.fwknop.FwknopBase64.encode;
import static org.apache.commons.codec.Charsets.UTF_8; | package net.seleucus.wsp.crypto.fwknop;
public class Message {
public static final char FIELD_DELIMITER = ':';
private final long randomValue;
private final String username;
private final long timestamp;
private final String version;
private final MessageType messageType;
private final String payload; | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopBase64.java
// public static String encode(byte[] input){
// return StringUtils.remove(Base64.encodeBase64String(input), CHAR_TO_REMOVE);
// }
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/Message.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static java.util.Objects.requireNonNull;
import static net.seleucus.wsp.crypto.fwknop.FwknopBase64.encode;
import static org.apache.commons.codec.Charsets.UTF_8;
package net.seleucus.wsp.crypto.fwknop;
public class Message {
public static final char FIELD_DELIMITER = ':';
private final long randomValue;
private final String username;
private final long timestamp;
private final String version;
private final MessageType messageType;
private final String payload; | private final DigestType digestType; |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/crypto/fwknop/Message.java | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopBase64.java
// public static String encode(byte[] input){
// return StringUtils.remove(Base64.encodeBase64String(input), CHAR_TO_REMOVE);
// }
| import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static java.util.Objects.requireNonNull;
import static net.seleucus.wsp.crypto.fwknop.FwknopBase64.encode;
import static org.apache.commons.codec.Charsets.UTF_8; | package net.seleucus.wsp.crypto.fwknop;
public class Message {
public static final char FIELD_DELIMITER = ':';
private final long randomValue;
private final String username;
private final long timestamp;
private final String version;
private final MessageType messageType;
private final String payload;
private final DigestType digestType;
Message(long randomValue, String username, long timestamp, String version, MessageType messageType, String payload, DigestType digestType) {
this.digestType = digestType;
this.randomValue = requireNonNull(randomValue);
this.username = requireNonNull(username);
this.timestamp = requireNonNull(timestamp);
this.version = requireNonNull(version);
this.messageType = requireNonNull(messageType);
this.payload = requireNonNull(payload);
}
public String encoded(){
return new StringBuilder()
.append(randomValue).append(FIELD_DELIMITER) | // Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/MessageType.java
// public enum MessageType {
//
// CommandMessage(0),
// AccessMessage(1),
// NatAccessMessage(2),
// ClientTimeOutAccessMessage(3),
// ClientTimeOutNatAccessMessage(4),
// LocalNatAccessMessage(5),
// ClientTimeoutLocalNatAccessMessage(6);
//
// private int id;
//
// private MessageType(int id) {
// this.id = id;
// }
//
// public int getId() {
// return id;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopBase64.java
// public static String encode(byte[] input){
// return StringUtils.remove(Base64.encodeBase64String(input), CHAR_TO_REMOVE);
// }
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/Message.java
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.MessageType;
import org.apache.commons.codec.binary.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static java.util.Objects.requireNonNull;
import static net.seleucus.wsp.crypto.fwknop.FwknopBase64.encode;
import static org.apache.commons.codec.Charsets.UTF_8;
package net.seleucus.wsp.crypto.fwknop;
public class Message {
public static final char FIELD_DELIMITER = ':';
private final long randomValue;
private final String username;
private final long timestamp;
private final String version;
private final MessageType messageType;
private final String payload;
private final DigestType digestType;
Message(long randomValue, String username, long timestamp, String version, MessageType messageType, String payload, DigestType digestType) {
this.digestType = digestType;
this.randomValue = requireNonNull(randomValue);
this.username = requireNonNull(username);
this.timestamp = requireNonNull(timestamp);
this.version = requireNonNull(version);
this.messageType = requireNonNull(messageType);
this.payload = requireNonNull(payload);
}
public String encoded(){
return new StringBuilder()
.append(randomValue).append(FIELD_DELIMITER) | .append(encode(username)).append(FIELD_DELIMITER) |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/filters/TimestampWebLogFilter.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/time/TimeSource.java
// public interface TimeSource {
//
// /**
// * Returns the number of seconds (UTC) since the epoch (1970-01-01T00:00:00Z)
// *
// * @return timestamp as a long representing seconds since epoch
// */
// long getTimestamp();
//
// long getTimestamp(final TimeUnit timeUnit);
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import net.seleucus.wsp.time.TimeSource; | package net.seleucus.wsp.server.request.filter.filters;
public class TimestampWebLogFilter implements WebLogFilter {
private final TimeSource timeSource;
private final long maxAgeSeconds;
public TimestampWebLogFilter(TimeSource timeSource, final long maxAgeSeconds) {
this.timeSource = timeSource;
this.maxAgeSeconds = maxAgeSeconds;
}
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/time/TimeSource.java
// public interface TimeSource {
//
// /**
// * Returns the number of seconds (UTC) since the epoch (1970-01-01T00:00:00Z)
// *
// * @return timestamp as a long representing seconds since epoch
// */
// long getTimestamp();
//
// long getTimestamp(final TimeUnit timeUnit);
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/filters/TimestampWebLogFilter.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import net.seleucus.wsp.time.TimeSource;
package net.seleucus.wsp.server.request.filter.filters;
public class TimestampWebLogFilter implements WebLogFilter {
private final TimeSource timeSource;
private final long maxAgeSeconds;
public TimestampWebLogFilter(TimeSource timeSource, final long maxAgeSeconds) {
this.timeSource = timeSource;
this.maxAgeSeconds = maxAgeSeconds;
}
@Override | public FilterResult parse(final LogMessage logMessage) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/server/request/filter/filters/TimestampWebLogFilter.java | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/time/TimeSource.java
// public interface TimeSource {
//
// /**
// * Returns the number of seconds (UTC) since the epoch (1970-01-01T00:00:00Z)
// *
// * @return timestamp as a long representing seconds since epoch
// */
// long getTimestamp();
//
// long getTimestamp(final TimeUnit timeUnit);
// }
| import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import net.seleucus.wsp.time.TimeSource; | package net.seleucus.wsp.server.request.filter.filters;
public class TimestampWebLogFilter implements WebLogFilter {
private final TimeSource timeSource;
private final long maxAgeSeconds;
public TimestampWebLogFilter(TimeSource timeSource, final long maxAgeSeconds) {
this.timeSource = timeSource;
this.maxAgeSeconds = maxAgeSeconds;
}
@Override | // Path: src/main/java/net/seleucus/wsp/server/request/domain/LogMessage.java
// public class LogMessage {
//
// private final String ipAddress;
// private final String userId;
// private final long timestamp;
// private final HttpMethod httpMethod;
// private final String requestUri;
// private final HttpVersion httpVersion;
// private final int responseCode;
// private final long responseSizeBytes;
//
// public LogMessage(final String ipAddress, final String userId, final long timestamp, final HttpMethod httpMethod,
// final String requestUri, final HttpVersion httpVersion, final int responseCode,
// final long responseSizeBytes) {
// this.ipAddress = ipAddress;
// this.userId = userId;
// this.timestamp = timestamp;
// this.httpMethod = httpMethod;
// this.requestUri = requestUri;
// this.httpVersion = httpVersion;
// this.responseCode = responseCode;
// this.responseSizeBytes = responseSizeBytes;
// }
//
// public String getIpAddress() {
// return ipAddress;
// }
//
// public String getUserId() {
// return userId;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public HttpMethod getHttpMethod() {
// return httpMethod;
// }
//
// public String getRequestUri() {
// return requestUri;
// }
//
// public HttpVersion getHttpVersion() {
// return httpVersion;
// }
//
// public int getResponseCode() {
// return responseCode;
// }
//
// public long getResponseSizeBytes() {
// return responseSizeBytes;
// }
//
// @Override
// public String toString() {
// return ReflectionToStringBuilder.toString(this);
// }
//
// public static class LogMessageBuilder {
// private String ipAddress;
// private String userId;
// private long timestamp;
// private HttpMethod httpMethod;
// private String requestUri;
// private HttpVersion httpVersion;
// private int responseCode;
// private long responseSizeBytes;
//
// public static LogMessageBuilder createLogMessage(){
// return new LogMessageBuilder();
// }
//
// public LogMessageBuilder withIpAddress(final String ipAddress) {
// this.ipAddress = ipAddress;
// return this;
// }
//
// public LogMessageBuilder withUserId(final String userId) {
// this.userId = userId;
// return this;
// }
//
// public LogMessageBuilder withTimestamp(final long timestamp) {
// this.timestamp = timestamp;
// return this;
// }
//
// public LogMessageBuilder withHttpMethod(final HttpMethod httpMethod) {
// this.httpMethod = httpMethod;
// return this;
// }
//
// public LogMessageBuilder withRequestUri(final String requestUri) {
// this.requestUri = requestUri;
// return this;
// }
//
// public LogMessageBuilder withHttpVersion(final HttpVersion httpVersion) {
// this.httpVersion = httpVersion;
// return this;
// }
//
// public LogMessageBuilder withResponseCode(final int responseCode) {
// this.responseCode = responseCode;
// return this;
// }
//
// public LogMessageBuilder withResponseSizeBytes(final long responseSizeBytes) {
// this.responseSizeBytes = responseSizeBytes;
// return this;
// }
//
// public LogMessage build(){
// return new LogMessage(ipAddress, userId, timestamp, httpMethod, requestUri, httpVersion, responseCode, responseSizeBytes);
// }
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/FilterResult.java
// public enum FilterResult {
// DROP, ACCEPT;
//
// public static boolean resultIsDrop(final FilterResult filterResult){
// return DROP == filterResult;
// }
//
// public static FilterResult evaluateCondition(boolean condition){
// return condition ? ACCEPT : DROP;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/server/request/filter/WebLogFilter.java
// public interface WebLogFilter {
//
// FilterResult parse(LogMessage logMessage);
//
// }
//
// Path: src/main/java/net/seleucus/wsp/time/TimeSource.java
// public interface TimeSource {
//
// /**
// * Returns the number of seconds (UTC) since the epoch (1970-01-01T00:00:00Z)
// *
// * @return timestamp as a long representing seconds since epoch
// */
// long getTimestamp();
//
// long getTimestamp(final TimeUnit timeUnit);
// }
// Path: src/main/java/net/seleucus/wsp/server/request/filter/filters/TimestampWebLogFilter.java
import net.seleucus.wsp.server.request.domain.LogMessage;
import net.seleucus.wsp.server.request.filter.FilterResult;
import net.seleucus.wsp.server.request.filter.WebLogFilter;
import net.seleucus.wsp.time.TimeSource;
package net.seleucus.wsp.server.request.filter.filters;
public class TimestampWebLogFilter implements WebLogFilter {
private final TimeSource timeSource;
private final long maxAgeSeconds;
public TimestampWebLogFilter(TimeSource timeSource, final long maxAgeSeconds) {
this.timeSource = timeSource;
this.maxAgeSeconds = maxAgeSeconds;
}
@Override | public FilterResult parse(final LogMessage logMessage) { |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoService.java | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaUtils.java
// public class WebSpaUtils {
//
// private static final int ITERATIONS = 1024;
//
// protected static byte[] digest(byte[] value) {
// for (int i = 0; i < ITERATIONS; i++) {
// value = DigestUtils.sha512(value);
// }
//
// return value;
// }
//
// protected static byte[] xor(final byte[] inputByteArray, final byte timeByte) {
// final byte[] outputByteArray = new byte[inputByteArray.length];
//
// for (int intCount = 0; intCount < inputByteArray.length; intCount++) {
// outputByteArray[intCount] = (byte) (inputByteArray[intCount] ^ timeByte);
// }
//
// return outputByteArray;
// }
//
// protected static boolean equals(byte[] first, byte[] second) {
// if(first == null && second == null){
// return false;
// }
// return Arrays.equals(first, second);
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionMode.java
// public enum EncryptionMode {
//
// ECB(1, "ECB"),
// CBC(2, "CBC"),
// CFB(3, "CFB"),
// PCBC(4, "PCBC"),
// OFB(5, "OFB"),
// CTR(6, "CTR");
//
// private final int id;
// private final String name;
//
// private EncryptionMode(final int id, final String name) {
// this.id = id;
// this.name = name;
// }
//
// public int id() {
// return id;
// }
//
// public String modeName() {
// return name;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionType.java
// public enum EncryptionType {
//
// AES(1, "AES", 16);
//
// private final int id;
// private final String name;
// private final int blockSize;
//
// private EncryptionType(final int id, final String name, int blockSize) {
// this.id = id;
// this.name = name;
// this.blockSize = blockSize;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return name;
// }
//
// public int getBlockSize() {
// return blockSize;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
| import net.seleucus.wsp.crypto.WebSpaUtils;
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import static javax.crypto.Cipher.DECRYPT_MODE;
import static javax.crypto.Cipher.ENCRYPT_MODE;
import static org.apache.commons.codec.Charsets.UTF_8; | package net.seleucus.wsp.crypto.fwknop;
/**
*
* @author pgolen
*/
public final class FwknopSymmetricCryptoService extends WebSpaUtils {
private static final String PADDING_STRATEGY = "PKCS5Padding";
private final static String FWKNOP_ENCRYPTION_HEADER = "U2FsdGVkX1";
private final static byte SALT_LEN = 8;
private final static byte IV_LEN = 16;
private final static byte KEY_LEN = 32;
private final SecureRandom secureRandom; | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaUtils.java
// public class WebSpaUtils {
//
// private static final int ITERATIONS = 1024;
//
// protected static byte[] digest(byte[] value) {
// for (int i = 0; i < ITERATIONS; i++) {
// value = DigestUtils.sha512(value);
// }
//
// return value;
// }
//
// protected static byte[] xor(final byte[] inputByteArray, final byte timeByte) {
// final byte[] outputByteArray = new byte[inputByteArray.length];
//
// for (int intCount = 0; intCount < inputByteArray.length; intCount++) {
// outputByteArray[intCount] = (byte) (inputByteArray[intCount] ^ timeByte);
// }
//
// return outputByteArray;
// }
//
// protected static boolean equals(byte[] first, byte[] second) {
// if(first == null && second == null){
// return false;
// }
// return Arrays.equals(first, second);
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionMode.java
// public enum EncryptionMode {
//
// ECB(1, "ECB"),
// CBC(2, "CBC"),
// CFB(3, "CFB"),
// PCBC(4, "PCBC"),
// OFB(5, "OFB"),
// CTR(6, "CTR");
//
// private final int id;
// private final String name;
//
// private EncryptionMode(final int id, final String name) {
// this.id = id;
// this.name = name;
// }
//
// public int id() {
// return id;
// }
//
// public String modeName() {
// return name;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionType.java
// public enum EncryptionType {
//
// AES(1, "AES", 16);
//
// private final int id;
// private final String name;
// private final int blockSize;
//
// private EncryptionType(final int id, final String name, int blockSize) {
// this.id = id;
// this.name = name;
// this.blockSize = blockSize;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return name;
// }
//
// public int getBlockSize() {
// return blockSize;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoService.java
import net.seleucus.wsp.crypto.WebSpaUtils;
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import static javax.crypto.Cipher.DECRYPT_MODE;
import static javax.crypto.Cipher.ENCRYPT_MODE;
import static org.apache.commons.codec.Charsets.UTF_8;
package net.seleucus.wsp.crypto.fwknop;
/**
*
* @author pgolen
*/
public final class FwknopSymmetricCryptoService extends WebSpaUtils {
private static final String PADDING_STRATEGY = "PKCS5Padding";
private final static String FWKNOP_ENCRYPTION_HEADER = "U2FsdGVkX1";
private final static byte SALT_LEN = 8;
private final static byte IV_LEN = 16;
private final static byte KEY_LEN = 32;
private final SecureRandom secureRandom; | private final EncryptionType encryptionType; |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoService.java | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaUtils.java
// public class WebSpaUtils {
//
// private static final int ITERATIONS = 1024;
//
// protected static byte[] digest(byte[] value) {
// for (int i = 0; i < ITERATIONS; i++) {
// value = DigestUtils.sha512(value);
// }
//
// return value;
// }
//
// protected static byte[] xor(final byte[] inputByteArray, final byte timeByte) {
// final byte[] outputByteArray = new byte[inputByteArray.length];
//
// for (int intCount = 0; intCount < inputByteArray.length; intCount++) {
// outputByteArray[intCount] = (byte) (inputByteArray[intCount] ^ timeByte);
// }
//
// return outputByteArray;
// }
//
// protected static boolean equals(byte[] first, byte[] second) {
// if(first == null && second == null){
// return false;
// }
// return Arrays.equals(first, second);
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionMode.java
// public enum EncryptionMode {
//
// ECB(1, "ECB"),
// CBC(2, "CBC"),
// CFB(3, "CFB"),
// PCBC(4, "PCBC"),
// OFB(5, "OFB"),
// CTR(6, "CTR");
//
// private final int id;
// private final String name;
//
// private EncryptionMode(final int id, final String name) {
// this.id = id;
// this.name = name;
// }
//
// public int id() {
// return id;
// }
//
// public String modeName() {
// return name;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionType.java
// public enum EncryptionType {
//
// AES(1, "AES", 16);
//
// private final int id;
// private final String name;
// private final int blockSize;
//
// private EncryptionType(final int id, final String name, int blockSize) {
// this.id = id;
// this.name = name;
// this.blockSize = blockSize;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return name;
// }
//
// public int getBlockSize() {
// return blockSize;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
| import net.seleucus.wsp.crypto.WebSpaUtils;
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import static javax.crypto.Cipher.DECRYPT_MODE;
import static javax.crypto.Cipher.ENCRYPT_MODE;
import static org.apache.commons.codec.Charsets.UTF_8; | package net.seleucus.wsp.crypto.fwknop;
/**
*
* @author pgolen
*/
public final class FwknopSymmetricCryptoService extends WebSpaUtils {
private static final String PADDING_STRATEGY = "PKCS5Padding";
private final static String FWKNOP_ENCRYPTION_HEADER = "U2FsdGVkX1";
private final static byte SALT_LEN = 8;
private final static byte IV_LEN = 16;
private final static byte KEY_LEN = 32;
private final SecureRandom secureRandom;
private final EncryptionType encryptionType; | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaUtils.java
// public class WebSpaUtils {
//
// private static final int ITERATIONS = 1024;
//
// protected static byte[] digest(byte[] value) {
// for (int i = 0; i < ITERATIONS; i++) {
// value = DigestUtils.sha512(value);
// }
//
// return value;
// }
//
// protected static byte[] xor(final byte[] inputByteArray, final byte timeByte) {
// final byte[] outputByteArray = new byte[inputByteArray.length];
//
// for (int intCount = 0; intCount < inputByteArray.length; intCount++) {
// outputByteArray[intCount] = (byte) (inputByteArray[intCount] ^ timeByte);
// }
//
// return outputByteArray;
// }
//
// protected static boolean equals(byte[] first, byte[] second) {
// if(first == null && second == null){
// return false;
// }
// return Arrays.equals(first, second);
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionMode.java
// public enum EncryptionMode {
//
// ECB(1, "ECB"),
// CBC(2, "CBC"),
// CFB(3, "CFB"),
// PCBC(4, "PCBC"),
// OFB(5, "OFB"),
// CTR(6, "CTR");
//
// private final int id;
// private final String name;
//
// private EncryptionMode(final int id, final String name) {
// this.id = id;
// this.name = name;
// }
//
// public int id() {
// return id;
// }
//
// public String modeName() {
// return name;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionType.java
// public enum EncryptionType {
//
// AES(1, "AES", 16);
//
// private final int id;
// private final String name;
// private final int blockSize;
//
// private EncryptionType(final int id, final String name, int blockSize) {
// this.id = id;
// this.name = name;
// this.blockSize = blockSize;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return name;
// }
//
// public int getBlockSize() {
// return blockSize;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoService.java
import net.seleucus.wsp.crypto.WebSpaUtils;
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import static javax.crypto.Cipher.DECRYPT_MODE;
import static javax.crypto.Cipher.ENCRYPT_MODE;
import static org.apache.commons.codec.Charsets.UTF_8;
package net.seleucus.wsp.crypto.fwknop;
/**
*
* @author pgolen
*/
public final class FwknopSymmetricCryptoService extends WebSpaUtils {
private static final String PADDING_STRATEGY = "PKCS5Padding";
private final static String FWKNOP_ENCRYPTION_HEADER = "U2FsdGVkX1";
private final static byte SALT_LEN = 8;
private final static byte IV_LEN = 16;
private final static byte KEY_LEN = 32;
private final SecureRandom secureRandom;
private final EncryptionType encryptionType; | private final EncryptionMode encryptionMode; |
OWASP/WebSpa | src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoService.java | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaUtils.java
// public class WebSpaUtils {
//
// private static final int ITERATIONS = 1024;
//
// protected static byte[] digest(byte[] value) {
// for (int i = 0; i < ITERATIONS; i++) {
// value = DigestUtils.sha512(value);
// }
//
// return value;
// }
//
// protected static byte[] xor(final byte[] inputByteArray, final byte timeByte) {
// final byte[] outputByteArray = new byte[inputByteArray.length];
//
// for (int intCount = 0; intCount < inputByteArray.length; intCount++) {
// outputByteArray[intCount] = (byte) (inputByteArray[intCount] ^ timeByte);
// }
//
// return outputByteArray;
// }
//
// protected static boolean equals(byte[] first, byte[] second) {
// if(first == null && second == null){
// return false;
// }
// return Arrays.equals(first, second);
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionMode.java
// public enum EncryptionMode {
//
// ECB(1, "ECB"),
// CBC(2, "CBC"),
// CFB(3, "CFB"),
// PCBC(4, "PCBC"),
// OFB(5, "OFB"),
// CTR(6, "CTR");
//
// private final int id;
// private final String name;
//
// private EncryptionMode(final int id, final String name) {
// this.id = id;
// this.name = name;
// }
//
// public int id() {
// return id;
// }
//
// public String modeName() {
// return name;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionType.java
// public enum EncryptionType {
//
// AES(1, "AES", 16);
//
// private final int id;
// private final String name;
// private final int blockSize;
//
// private EncryptionType(final int id, final String name, int blockSize) {
// this.id = id;
// this.name = name;
// this.blockSize = blockSize;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return name;
// }
//
// public int getBlockSize() {
// return blockSize;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
| import net.seleucus.wsp.crypto.WebSpaUtils;
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import static javax.crypto.Cipher.DECRYPT_MODE;
import static javax.crypto.Cipher.ENCRYPT_MODE;
import static org.apache.commons.codec.Charsets.UTF_8; | package net.seleucus.wsp.crypto.fwknop;
/**
*
* @author pgolen
*/
public final class FwknopSymmetricCryptoService extends WebSpaUtils {
private static final String PADDING_STRATEGY = "PKCS5Padding";
private final static String FWKNOP_ENCRYPTION_HEADER = "U2FsdGVkX1";
private final static byte SALT_LEN = 8;
private final static byte IV_LEN = 16;
private final static byte KEY_LEN = 32;
private final SecureRandom secureRandom;
private final EncryptionType encryptionType;
private final EncryptionMode encryptionMode; | // Path: src/main/java/net/seleucus/wsp/crypto/WebSpaUtils.java
// public class WebSpaUtils {
//
// private static final int ITERATIONS = 1024;
//
// protected static byte[] digest(byte[] value) {
// for (int i = 0; i < ITERATIONS; i++) {
// value = DigestUtils.sha512(value);
// }
//
// return value;
// }
//
// protected static byte[] xor(final byte[] inputByteArray, final byte timeByte) {
// final byte[] outputByteArray = new byte[inputByteArray.length];
//
// for (int intCount = 0; intCount < inputByteArray.length; intCount++) {
// outputByteArray[intCount] = (byte) (inputByteArray[intCount] ^ timeByte);
// }
//
// return outputByteArray;
// }
//
// protected static boolean equals(byte[] first, byte[] second) {
// if(first == null && second == null){
// return false;
// }
// return Arrays.equals(first, second);
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/DigestType.java
// public enum DigestType {
//
// MD5(1, "MD5"),
// SHA1(2, "SHA-1"),
// SHA256(3, "SHA-256"),
// SHA384(4, "SHA-384"),
// SHA512(5, "SHA-512");
//
// private final int id;
// private final String algorithmName;
//
// private DigestType(final int id, final String algorithmName) {
// this.id = id;
// this.algorithmName = algorithmName;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionMode.java
// public enum EncryptionMode {
//
// ECB(1, "ECB"),
// CBC(2, "CBC"),
// CFB(3, "CFB"),
// PCBC(4, "PCBC"),
// OFB(5, "OFB"),
// CTR(6, "CTR");
//
// private final int id;
// private final String name;
//
// private EncryptionMode(final int id, final String name) {
// this.id = id;
// this.name = name;
// }
//
// public int id() {
// return id;
// }
//
// public String modeName() {
// return name;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/EncryptionType.java
// public enum EncryptionType {
//
// AES(1, "AES", 16);
//
// private final int id;
// private final String name;
// private final int blockSize;
//
// private EncryptionType(final int id, final String name, int blockSize) {
// this.id = id;
// this.name = name;
// this.blockSize = blockSize;
// }
//
// public int getId() {
// return id;
// }
//
// public String algorithmName() {
// return name;
// }
//
// public int getBlockSize() {
// return blockSize;
// }
// }
//
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/fields/HmacType.java
// public enum HmacType {
//
// HmacMD5(0, "HmacMD5", 16, 22),
// HmacSHA1(1, "HmacSHA1", 20, 27),
// HmacSHA256(2, "HmacSHA256", 32, 43),
// HmacSHA384(3, "HmacSHA384", 48, 64),
// HmacSHA512(4, "HmacSHA512", 64, 86);
//
// private final int id;
// private final String algorithmName;
// private final int length;
// private final int base64Length;
//
// private HmacType(int id, String algorithmName, int length, int base64Length) {
// this.id = id;
// this.algorithmName = algorithmName;
// this.length = length;
// this.base64Length = base64Length;
// }
//
// public int id() {
// return id;
// }
//
// public String algorithmName() {
// return algorithmName;
// }
//
// public int length() {
// return length;
// }
//
// public int base64Length(){
// return base64Length;
// }
// }
// Path: src/main/java/net/seleucus/wsp/crypto/fwknop/FwknopSymmetricCryptoService.java
import net.seleucus.wsp.crypto.WebSpaUtils;
import net.seleucus.wsp.crypto.fwknop.fields.DigestType;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionMode;
import net.seleucus.wsp.crypto.fwknop.fields.EncryptionType;
import net.seleucus.wsp.crypto.fwknop.fields.HmacType;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import static javax.crypto.Cipher.DECRYPT_MODE;
import static javax.crypto.Cipher.ENCRYPT_MODE;
import static org.apache.commons.codec.Charsets.UTF_8;
package net.seleucus.wsp.crypto.fwknop;
/**
*
* @author pgolen
*/
public final class FwknopSymmetricCryptoService extends WebSpaUtils {
private static final String PADDING_STRATEGY = "PKCS5Padding";
private final static String FWKNOP_ENCRYPTION_HEADER = "U2FsdGVkX1";
private final static byte SALT_LEN = 8;
private final static byte IV_LEN = 16;
private final static byte KEY_LEN = 32;
private final SecureRandom secureRandom;
private final EncryptionType encryptionType;
private final EncryptionMode encryptionMode; | private final DigestType digestType; |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/config/WSConfigurationTest.java | // Path: src/main/java/net/seleucus/wsp/util/WSConstants.java
// public class WSConstants {
//
// public static final String LOGGING_REGEX_FOR_EACH_REQUEST = "logging-regex-for-each-request";
// public static final String ACCESS_LOG_FILE_LOCATION = "access-log-file-location";
//
// }
| import static org.junit.Assert.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Properties;
import net.seleucus.wsp.util.WSConstants;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; | File configFile = new File(WSConfiguration.CONFIG_PATH);
// Running the constructor, creates the file
// "webspa-config.properties" if one does
// not exist
assertTrue(configFile.exists());
}
@Test
public void testWSConfigurationShouldNotCreateAFileIfOneExists() throws IOException {
new WSConfiguration();
new WSConfiguration();
File configFile = new File(WSConfiguration.CONFIG_PATH);
// Call the constructor twice, thus creating the file
assertTrue(configFile.exists());
}
@Test
public void testWSConfigurationHasTheAccessLogFileLocationProperty() throws IOException {
new WSConfiguration();
File configFile = new File(WSConfiguration.CONFIG_PATH);
FileInputStream in = new FileInputStream(configFile);
Properties configProperties = new Properties();
configProperties.load(in);
in.close();
| // Path: src/main/java/net/seleucus/wsp/util/WSConstants.java
// public class WSConstants {
//
// public static final String LOGGING_REGEX_FOR_EACH_REQUEST = "logging-regex-for-each-request";
// public static final String ACCESS_LOG_FILE_LOCATION = "access-log-file-location";
//
// }
// Path: src/test/java/net/seleucus/wsp/config/WSConfigurationTest.java
import static org.junit.Assert.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Properties;
import net.seleucus.wsp.util.WSConstants;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
File configFile = new File(WSConfiguration.CONFIG_PATH);
// Running the constructor, creates the file
// "webspa-config.properties" if one does
// not exist
assertTrue(configFile.exists());
}
@Test
public void testWSConfigurationShouldNotCreateAFileIfOneExists() throws IOException {
new WSConfiguration();
new WSConfiguration();
File configFile = new File(WSConfiguration.CONFIG_PATH);
// Call the constructor twice, thus creating the file
assertTrue(configFile.exists());
}
@Test
public void testWSConfigurationHasTheAccessLogFileLocationProperty() throws IOException {
new WSConfiguration();
File configFile = new File(WSConfiguration.CONFIG_PATH);
FileInputStream in = new FileInputStream(configFile);
Properties configProperties = new Properties();
configProperties.load(in);
in.close();
| assertTrue(configProperties.containsKey(WSConstants.ACCESS_LOG_FILE_LOCATION)); |
OWASP/WebSpa | src/test/java/net/seleucus/wsp/main/WSVersionTest.java | // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
| import net.seleucus.wsp.console.WSConsole;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.sql.SQLException;
import static org.junit.Assert.*; | assertTrue(
"Major version is between [0,10): " + minorVersion,
( (minorVersion >= VERSION_MIN) && (minorVersion < VERSION_MAX) )
);
}
@Test
public final void testGetValue() {
assertEquals(WSVersion.getValue(), WSVersion.getMajor() + "." + WSVersion.getMinor());
}
@Test
public final void shouldBe3Characters() {
String version = WSVersion.getValue();
assertEquals(3, version.length());
}
@Test
public final void testIsValidTrue() {
assertTrue(WSVersion.isCurrentVersion("0.8"));
}
@Test
public final void testIsValidFalse() {
assertFalse(WSVersion.isCurrentVersion("0.4"));
}
@Test
public void testRunConsole() throws SQLException {
| // Path: src/main/java/net/seleucus/wsp/console/WSConsole.java
// public abstract class WSConsole {
//
// public static final WSConsole getWsConsole() {
// if (System.console() != null) {
// return new WSConsoleNative();
// } else {
// return new WSConsoleInOut();
// }
// }
//
// public abstract String readLine(String string);
//
// public abstract char[] readPassword(String string);
//
// public abstract void println(String string);
//
// }
// Path: src/test/java/net/seleucus/wsp/main/WSVersionTest.java
import net.seleucus.wsp.console.WSConsole;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.sql.SQLException;
import static org.junit.Assert.*;
assertTrue(
"Major version is between [0,10): " + minorVersion,
( (minorVersion >= VERSION_MIN) && (minorVersion < VERSION_MAX) )
);
}
@Test
public final void testGetValue() {
assertEquals(WSVersion.getValue(), WSVersion.getMajor() + "." + WSVersion.getMinor());
}
@Test
public final void shouldBe3Characters() {
String version = WSVersion.getValue();
assertEquals(3, version.length());
}
@Test
public final void testIsValidTrue() {
assertTrue(WSVersion.isCurrentVersion("0.8"));
}
@Test
public final void testIsValidFalse() {
assertFalse(WSVersion.isCurrentVersion("0.4"));
}
@Test
public void testRunConsole() throws SQLException {
| WSVersion myVersion = new WSVersion(new WebSpa(WSConsole.getWsConsole())); |
nurv/BicaVM | runtime/foo.java | // Path: runtime/bicavm/browser/Window.java
// public class Window{
// public static native void setTitle(String title);
// }
| import bicavm.browser.Window; |
public class foo{
public static void main(String[] args){
String hello = "bicavm";
String world = " changed this title"; | // Path: runtime/bicavm/browser/Window.java
// public class Window{
// public static native void setTitle(String title);
// }
// Path: runtime/foo.java
import bicavm.browser.Window;
public class foo{
public static void main(String[] args){
String hello = "bicavm";
String world = " changed this title"; | Window.setTitle(hello + world); |
unitsofmeasurement/uom-systems | unicode/src/main/java/systems/uom/unicode/CLDR.java | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
| import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*; | */
public static final Unit<Length> PIXEL = addUnit(METRE.multiply(0.0002636));
/**
* A unit of length equal to <code>0.013837 {@link #INCH}</code> exactly (standard name <code>pt</code>).
*
* @see #PIXEL
* @stable ICU 59
*/
public static final Unit<Length> POINT = addUnit(LINE.divide(6), "Point", "pt"); //
// static final Unit<Length> POINT = addUnit(INCH.multiply(13837) //
// .divide(1000000));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. public
* static final Unit<Length> PICA = addUnit(POINT.multiply(12)); /** As per
* <a href="http//cldr.unicode.org/">CLDR</a> standard. public static final
* Unit<Length> POINT_PRINTER =
* addUnit(INCH_INTERNATIONAL.multiply(13837).divide(1000000)); /** As per
* <a href="http//cldr.unicode.org/">CLDR</a> standard. public static final
* Unit<Length> PICA_PRINTER = addUnit(POINT_PRINTER.multiply(12));
*/
/**
* Pixel per centimeter describe the resolution for any output device (monitor,
* printer) that deals with outputting digital raster images.
*
* @see #DOT
* @see #METER
* @stable ICU 65
*/ | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
// Path: unicode/src/main/java/systems/uom/unicode/CLDR.java
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*;
*/
public static final Unit<Length> PIXEL = addUnit(METRE.multiply(0.0002636));
/**
* A unit of length equal to <code>0.013837 {@link #INCH}</code> exactly (standard name <code>pt</code>).
*
* @see #PIXEL
* @stable ICU 59
*/
public static final Unit<Length> POINT = addUnit(LINE.divide(6), "Point", "pt"); //
// static final Unit<Length> POINT = addUnit(INCH.multiply(13837) //
// .divide(1000000));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. public
* static final Unit<Length> PICA = addUnit(POINT.multiply(12)); /** As per
* <a href="http//cldr.unicode.org/">CLDR</a> standard. public static final
* Unit<Length> POINT_PRINTER =
* addUnit(INCH_INTERNATIONAL.multiply(13837).divide(1000000)); /** As per
* <a href="http//cldr.unicode.org/">CLDR</a> standard. public static final
* Unit<Length> PICA_PRINTER = addUnit(POINT_PRINTER.multiply(12));
*/
/**
* Pixel per centimeter describe the resolution for any output device (monitor,
* printer) that deals with outputting digital raster images.
*
* @see #DOT
* @see #METER
* @stable ICU 65
*/ | public static final Unit<Resolution> DOT_PER_CENTIMETER = addUnit(DOT.divide(CENTI(METER)).asType(Resolution.class), |
unitsofmeasurement/uom-systems | unicode/src/main/java/systems/uom/unicode/CLDR.java | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
| import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*; | *
* @stable ICU 65.
*/
public static final Unit<Energy> THERM_US = addUnit(JOULE.multiply(1.055e+8));
/**
* Constant for unit of power: horsepower
*
* @stable ICU 53
*/
public static final Unit<Power> HORSEPOWER = addUnit(new ProductUnit<Power>(FOOT_INTERNATIONAL.multiply(POUND_FORCE).divide(SECOND)));
/**
* Constant for unit of pressure: pound-per-square-inch
*
* @stable ICU 54
*/
public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit(new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2))));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
// private static final Unit<Angle> CIRCLE = new
// ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2)));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
public static final Unit<SolidAngle> SPHERE = addUnit(new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
/**
* The unit for binary information (standard name <code>bit</code>).
*
* @stable ICU 54
*/ | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
// Path: unicode/src/main/java/systems/uom/unicode/CLDR.java
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*;
*
* @stable ICU 65.
*/
public static final Unit<Energy> THERM_US = addUnit(JOULE.multiply(1.055e+8));
/**
* Constant for unit of power: horsepower
*
* @stable ICU 53
*/
public static final Unit<Power> HORSEPOWER = addUnit(new ProductUnit<Power>(FOOT_INTERNATIONAL.multiply(POUND_FORCE).divide(SECOND)));
/**
* Constant for unit of pressure: pound-per-square-inch
*
* @stable ICU 54
*/
public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit(new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2))));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
// private static final Unit<Angle> CIRCLE = new
// ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2)));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
public static final Unit<SolidAngle> SPHERE = addUnit(new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
/**
* The unit for binary information (standard name <code>bit</code>).
*
* @stable ICU 54
*/ | public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), "Bit", "bit", Information.class); |
unitsofmeasurement/uom-systems | unicode/src/main/java/systems/uom/unicode/CLDR.java | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
| import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*; | /**
* Constant for unit of pressure: pound-per-square-inch
*
* @stable ICU 54
*/
public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit(new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2))));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
// private static final Unit<Angle> CIRCLE = new
// ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2)));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
public static final Unit<SolidAngle> SPHERE = addUnit(new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
/**
* The unit for binary information (standard name <code>bit</code>).
*
* @stable ICU 54
*/
public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), "Bit", "bit", Information.class);
/**
* A unit of data amount equal to <code>8 {@link #BIT}</code> (BinarY TErm, standard name <code>byte</code>).
*/
public static final Unit<Information> BYTE = addUnit(BIT.multiply(8), "Byte", "byte");
/**
* The unit for binary information rate (standard name <code>bit/s</code>).
*
* @draft Non-ICU
*/ | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
// Path: unicode/src/main/java/systems/uom/unicode/CLDR.java
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*;
/**
* Constant for unit of pressure: pound-per-square-inch
*
* @stable ICU 54
*/
public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit(new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2))));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
// private static final Unit<Angle> CIRCLE = new
// ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2)));
/** As per <a href="http//cldr.unicode.org/">CLDR</a> standard. */
public static final Unit<SolidAngle> SPHERE = addUnit(new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
/**
* The unit for binary information (standard name <code>bit</code>).
*
* @stable ICU 54
*/
public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), "Bit", "bit", Information.class);
/**
* A unit of data amount equal to <code>8 {@link #BIT}</code> (BinarY TErm, standard name <code>byte</code>).
*/
public static final Unit<Information> BYTE = addUnit(BIT.multiply(8), "Byte", "byte");
/**
* The unit for binary information rate (standard name <code>bit/s</code>).
*
* @draft Non-ICU
*/ | static final Unit<InformationRate> BIT_PER_SECOND = addUnit(new ProductUnit<InformationRate>(BIT.divide(SECOND)), InformationRate.class); |
unitsofmeasurement/uom-systems | unicode/src/main/java/systems/uom/unicode/CLDR.java | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
| import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*; | public static final Unit<Information> BYTE = addUnit(BIT.multiply(8), "Byte", "byte");
/**
* The unit for binary information rate (standard name <code>bit/s</code>).
*
* @draft Non-ICU
*/
static final Unit<InformationRate> BIT_PER_SECOND = addUnit(new ProductUnit<InformationRate>(BIT.divide(SECOND)), InformationRate.class);
/**
* Equivalent {@link #BYTE}
*/
static final Unit<Information> OCTET = BYTE;
/**
* A unit used to measure the frequency (rate) at which an imaging device produces unique consecutive images (standard name <code>fps</code>).
*
* @draft Non-ICU
*/
static final Unit<Frequency> FRAME_PER_SECOND = ONE.divide(SECOND).asType(Frequency.class);
///////////////////
// Concentration //
///////////////////
/**
* Constant for unit of concentr: milligram-per-deciliter
*
* @stable ICU 57
*/
@SuppressWarnings("unchecked") | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
// Path: unicode/src/main/java/systems/uom/unicode/CLDR.java
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*;
public static final Unit<Information> BYTE = addUnit(BIT.multiply(8), "Byte", "byte");
/**
* The unit for binary information rate (standard name <code>bit/s</code>).
*
* @draft Non-ICU
*/
static final Unit<InformationRate> BIT_PER_SECOND = addUnit(new ProductUnit<InformationRate>(BIT.divide(SECOND)), InformationRate.class);
/**
* Equivalent {@link #BYTE}
*/
static final Unit<Information> OCTET = BYTE;
/**
* A unit used to measure the frequency (rate) at which an imaging device produces unique consecutive images (standard name <code>fps</code>).
*
* @draft Non-ICU
*/
static final Unit<Frequency> FRAME_PER_SECOND = ONE.divide(SECOND).asType(Frequency.class);
///////////////////
// Concentration //
///////////////////
/**
* Constant for unit of concentr: milligram-per-deciliter
*
* @stable ICU 57
*/
@SuppressWarnings("unchecked") | public static final Unit<Concentration<Mass>> MILLIGRAM_PER_DECILITER = addUnit(MILLI(GRAM).divide(DECI(LITER)).asType(Concentration.class)); |
unitsofmeasurement/uom-systems | unicode/src/main/java/systems/uom/unicode/CLDR.java | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
| import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*; | static final Unit<Information> OCTET = BYTE;
/**
* A unit used to measure the frequency (rate) at which an imaging device produces unique consecutive images (standard name <code>fps</code>).
*
* @draft Non-ICU
*/
static final Unit<Frequency> FRAME_PER_SECOND = ONE.divide(SECOND).asType(Frequency.class);
///////////////////
// Concentration //
///////////////////
/**
* Constant for unit of concentr: milligram-per-deciliter
*
* @stable ICU 57
*/
@SuppressWarnings("unchecked")
public static final Unit<Concentration<Mass>> MILLIGRAM_PER_DECILITER = addUnit(MILLI(GRAM).divide(DECI(LITER)).asType(Concentration.class));
///////////////////
// Consumption //
///////////////////
/**
* Constant for unit of consumption: liter-per-100kilometers
*
* @draft ICU 56
* @provisional This API might change or be removed in a future release.
*/
@SuppressWarnings("unchecked") | // Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Consumption.java
// public interface Consumption<Q extends Quantity<Q>> extends Quantity<Consumption<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Resolution.java
// public interface Resolution extends Quantity<Resolution> {
// }
// Path: unicode/src/main/java/systems/uom/unicode/CLDR.java
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.AbstractUnit.ONE;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Consumption;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import systems.uom.quantity.Resolution;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*;
static final Unit<Information> OCTET = BYTE;
/**
* A unit used to measure the frequency (rate) at which an imaging device produces unique consecutive images (standard name <code>fps</code>).
*
* @draft Non-ICU
*/
static final Unit<Frequency> FRAME_PER_SECOND = ONE.divide(SECOND).asType(Frequency.class);
///////////////////
// Concentration //
///////////////////
/**
* Constant for unit of concentr: milligram-per-deciliter
*
* @stable ICU 57
*/
@SuppressWarnings("unchecked")
public static final Unit<Concentration<Mass>> MILLIGRAM_PER_DECILITER = addUnit(MILLI(GRAM).divide(DECI(LITER)).asType(Concentration.class));
///////////////////
// Consumption //
///////////////////
/**
* Constant for unit of consumption: liter-per-100kilometers
*
* @draft ICU 56
* @provisional This API might change or be removed in a future release.
*/
@SuppressWarnings("unchecked") | public static final Unit<Consumption<Volume>> LITER_PER_100KILOMETERS = addUnit( |
unitsofmeasurement/uom-systems | ucum/src/main/java/systems/uom/ucum/UCUM.java | // Path: quantity/src/main/java/systems/uom/quantity/Acidity.java
// public interface Acidity extends Quantity<Acidity> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Drag.java
// public interface Drag extends Quantity<Drag> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
| import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.AbstractUnit.ONE;
import si.uom.quantity.*;
import systems.uom.quantity.Acidity;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Drag;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import si.uom.quantity.Level;
import si.uom.SI;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.LogConverter;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*; | // UNDEFINED;
// public static final Unit
// HOMEOPATHIC_POTENCY_OF_QUINTAMILLESIMAL_HAHNEMANNIAN = UNDEFINED;
// public static final Unit HOMEOPATHIC_POTENCY_OF_DECIMAL_KORSAKOVIAN =
// UNDEFINED;
// public static final Unit HOMEOPATHIC_POTENCY_OF_CENTESIMAL_KORSAKOVIAN =
// UNDEFINED;
// public static final Unit HOMEOPATHIC_POTENCY_OF_MILLESIMAL_KORSAKOVIAN =
// UNDEFINED;
// public static final Unit
// HOMEOPATHIC_POTENCY_OF_QUINTAMILLESIMAL_KORSAKOVIAN = UNDEFINED;
//////////////////////////////////////////////////
// CHEMICAL AND BIOCHEMICAL UNITS: UCUM 4.5 §45 //
//////////////////////////////////////////////////
/**
* amount of substance
* @since 2.4
*/
public static final Unit<AmountOfSubstance> EQUIVALENTS = addUnit(new AlternateUnit<AmountOfSubstance>(MOLE, "eq"));
/**
* amount of substance (dissolved particles)
* @since 2.4
*/
public static final Unit<AmountOfSubstance> OSMOLE = addUnit(new AlternateUnit<AmountOfSubstance>(MOLE, "osm"));
public static final Unit<Acidity> PH = addUnit(
MOLE.divide(LITER).transform(new LogConverter(10)).multiply(-1).asType(Acidity.class));
@SuppressWarnings("unchecked") | // Path: quantity/src/main/java/systems/uom/quantity/Acidity.java
// public interface Acidity extends Quantity<Acidity> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Drag.java
// public interface Drag extends Quantity<Drag> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
// Path: ucum/src/main/java/systems/uom/ucum/UCUM.java
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.AbstractUnit.ONE;
import si.uom.quantity.*;
import systems.uom.quantity.Acidity;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Drag;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import si.uom.quantity.Level;
import si.uom.SI;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.LogConverter;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*;
// UNDEFINED;
// public static final Unit
// HOMEOPATHIC_POTENCY_OF_QUINTAMILLESIMAL_HAHNEMANNIAN = UNDEFINED;
// public static final Unit HOMEOPATHIC_POTENCY_OF_DECIMAL_KORSAKOVIAN =
// UNDEFINED;
// public static final Unit HOMEOPATHIC_POTENCY_OF_CENTESIMAL_KORSAKOVIAN =
// UNDEFINED;
// public static final Unit HOMEOPATHIC_POTENCY_OF_MILLESIMAL_KORSAKOVIAN =
// UNDEFINED;
// public static final Unit
// HOMEOPATHIC_POTENCY_OF_QUINTAMILLESIMAL_KORSAKOVIAN = UNDEFINED;
//////////////////////////////////////////////////
// CHEMICAL AND BIOCHEMICAL UNITS: UCUM 4.5 §45 //
//////////////////////////////////////////////////
/**
* amount of substance
* @since 2.4
*/
public static final Unit<AmountOfSubstance> EQUIVALENTS = addUnit(new AlternateUnit<AmountOfSubstance>(MOLE, "eq"));
/**
* amount of substance (dissolved particles)
* @since 2.4
*/
public static final Unit<AmountOfSubstance> OSMOLE = addUnit(new AlternateUnit<AmountOfSubstance>(MOLE, "osm"));
public static final Unit<Acidity> PH = addUnit(
MOLE.divide(LITER).transform(new LogConverter(10)).multiply(-1).asType(Acidity.class));
@SuppressWarnings("unchecked") | public static final Unit<Concentration<Mass>> GRAM_PERCENT = addUnit( |
unitsofmeasurement/uom-systems | ucum/src/main/java/systems/uom/ucum/UCUM.java | // Path: quantity/src/main/java/systems/uom/quantity/Acidity.java
// public interface Acidity extends Quantity<Acidity> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Drag.java
// public interface Drag extends Quantity<Drag> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
| import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.AbstractUnit.ONE;
import si.uom.quantity.*;
import systems.uom.quantity.Acidity;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Drag;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import si.uom.quantity.Level;
import si.uom.SI;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.LogConverter;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*; | /** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Pressure> ATMOSPHERE_TECHNICAL = addUnit(
new ProductUnit<Pressure>(KILO(GRAM_FORCE).divide(CENTI(METER).pow(2))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<ElectricConductance> MHO = addUnit(
new AlternateUnit<ElectricConductance>(TMP_MHO, TMP_MHO.getSymbol()));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit(
new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Angle> CIRCLE = addUnit(new ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<SolidAngle> SPHERE = addUnit(
new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Mass> CARAT_METRIC = addUnit(GRAM.divide(5));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Dimensionless> CARAT_GOLD = addUnit(ONE.divide(24));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Length> SMOOT = addUnit(INCH_INTERNATIONAL.multiply(67));
////////////////////////////////////////////////
// INFORMATION TECHNOLOGY UNITS: UCUM 4.6 §48 //
////////////////////////////////////////////////
/**
* The unit for binary information (standard name <code>bit</code>).
* As per <a href="http://unitsofmeasure.org/">UCUM</a> standard.
*/ | // Path: quantity/src/main/java/systems/uom/quantity/Acidity.java
// public interface Acidity extends Quantity<Acidity> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Drag.java
// public interface Drag extends Quantity<Drag> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
// Path: ucum/src/main/java/systems/uom/ucum/UCUM.java
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.AbstractUnit.ONE;
import si.uom.quantity.*;
import systems.uom.quantity.Acidity;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Drag;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import si.uom.quantity.Level;
import si.uom.SI;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.LogConverter;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*;
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Pressure> ATMOSPHERE_TECHNICAL = addUnit(
new ProductUnit<Pressure>(KILO(GRAM_FORCE).divide(CENTI(METER).pow(2))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<ElectricConductance> MHO = addUnit(
new AlternateUnit<ElectricConductance>(TMP_MHO, TMP_MHO.getSymbol()));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Pressure> POUND_PER_SQUARE_INCH = addUnit(
new ProductUnit<Pressure>(POUND_FORCE.divide(INCH_INTERNATIONAL.pow(2))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Angle> CIRCLE = addUnit(new ProductUnit<Angle>(PI.multiply(RADIAN.multiply(2))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<SolidAngle> SPHERE = addUnit(
new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Mass> CARAT_METRIC = addUnit(GRAM.divide(5));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Dimensionless> CARAT_GOLD = addUnit(ONE.divide(24));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Length> SMOOT = addUnit(INCH_INTERNATIONAL.multiply(67));
////////////////////////////////////////////////
// INFORMATION TECHNOLOGY UNITS: UCUM 4.6 §48 //
////////////////////////////////////////////////
/**
* The unit for binary information (standard name <code>bit</code>).
* As per <a href="http://unitsofmeasure.org/">UCUM</a> standard.
*/ | public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), Information.class); |
unitsofmeasurement/uom-systems | ucum/src/main/java/systems/uom/ucum/UCUM.java | // Path: quantity/src/main/java/systems/uom/quantity/Acidity.java
// public interface Acidity extends Quantity<Acidity> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Drag.java
// public interface Drag extends Quantity<Drag> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
| import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.AbstractUnit.ONE;
import si.uom.quantity.*;
import systems.uom.quantity.Acidity;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Drag;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import si.uom.quantity.Level;
import si.uom.SI;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.LogConverter;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*; | new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Mass> CARAT_METRIC = addUnit(GRAM.divide(5));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Dimensionless> CARAT_GOLD = addUnit(ONE.divide(24));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Length> SMOOT = addUnit(INCH_INTERNATIONAL.multiply(67));
////////////////////////////////////////////////
// INFORMATION TECHNOLOGY UNITS: UCUM 4.6 §48 //
////////////////////////////////////////////////
/**
* The unit for binary information (standard name <code>bit</code>).
* As per <a href="http://unitsofmeasure.org/">UCUM</a> standard.
*/
public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), Information.class);
/**
* The bit is defined twice. One definition with a subscript letter ‘s‘ is defined as the logarithmus dualis of the number of distinct signals. However this unit can not practically be used to express more than 1000 bits. Especially when the bit is used to express transmission rate or memory capacities, floating point registers would quickly overflow. Therefore we define a second symbol for bit, without the suffix, to be the dimensionless unit 1.
* @since 2.3
*/
public static final Unit<Information> BIT_S = addUnit(new AlternateUnit<Information>(BIT, "bit\\u2082"));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Information> BYTE = addUnit(BIT.multiply(8));
/**
* The SI unit for binary information rate (standard name
* <code>bit/s</code>).
*/ | // Path: quantity/src/main/java/systems/uom/quantity/Acidity.java
// public interface Acidity extends Quantity<Acidity> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Concentration.java
// public interface Concentration<Q extends Quantity<Q>> extends Quantity<Concentration<Q>> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Drag.java
// public interface Drag extends Quantity<Drag> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/Information.java
// public interface Information extends Quantity<Information> {
// }
//
// Path: quantity/src/main/java/systems/uom/quantity/InformationRate.java
// public interface InformationRate extends Quantity<InformationRate> {
// }
// Path: ucum/src/main/java/systems/uom/ucum/UCUM.java
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.AbstractUnit.ONE;
import si.uom.quantity.*;
import systems.uom.quantity.Acidity;
import systems.uom.quantity.Concentration;
import systems.uom.quantity.Drag;
import systems.uom.quantity.Information;
import systems.uom.quantity.InformationRate;
import si.uom.quantity.Level;
import si.uom.SI;
import tech.units.indriya.*;
import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.function.LogConverter;
import tech.units.indriya.function.MultiplyConverter;
import tech.units.indriya.unit.AlternateUnit;
import tech.units.indriya.unit.ProductUnit;
import tech.units.indriya.unit.TransformedUnit;
import tech.units.indriya.unit.Units;
import javax.measure.Quantity;
import javax.measure.Unit;
import javax.measure.quantity.*;
new ProductUnit<SolidAngle>(PI.multiply(STERADIAN.multiply(4))));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Mass> CARAT_METRIC = addUnit(GRAM.divide(5));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Dimensionless> CARAT_GOLD = addUnit(ONE.divide(24));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Length> SMOOT = addUnit(INCH_INTERNATIONAL.multiply(67));
////////////////////////////////////////////////
// INFORMATION TECHNOLOGY UNITS: UCUM 4.6 §48 //
////////////////////////////////////////////////
/**
* The unit for binary information (standard name <code>bit</code>).
* As per <a href="http://unitsofmeasure.org/">UCUM</a> standard.
*/
public static final Unit<Information> BIT = addUnit(new AlternateUnit<Information>(ONE, "bit"), Information.class);
/**
* The bit is defined twice. One definition with a subscript letter ‘s‘ is defined as the logarithmus dualis of the number of distinct signals. However this unit can not practically be used to express more than 1000 bits. Especially when the bit is used to express transmission rate or memory capacities, floating point registers would quickly overflow. Therefore we define a second symbol for bit, without the suffix, to be the dimensionless unit 1.
* @since 2.3
*/
public static final Unit<Information> BIT_S = addUnit(new AlternateUnit<Information>(BIT, "bit\\u2082"));
/** As per <a href="http://unitsofmeasure.org/">UCUM</a> standard. */
public static final Unit<Information> BYTE = addUnit(BIT.multiply(8));
/**
* The SI unit for binary information rate (standard name
* <code>bit/s</code>).
*/ | protected static final ProductUnit<InformationRate> BITS_PER_SECOND = addUnit( |
unitsofmeasurement/uom-systems | common/src/test/java/systems/uom/common/USTest.java | // Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Length> METER = addUnit(METRE);
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Mass> POUND = addUnit(KILOGRAM.multiply(45359237).divide(100000000), "Pound", "lb"); // ,
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(745.69987158227), "Horsepower", "hp");
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> ELECTRICAL_HORSEPOWER = addUnit(WATT.multiply(746), "Horsepower (Electrical)", "hp(E)");
| import static org.junit.jupiter.api.Assertions.assertNull;
import static systems.uom.common.USCustomary.METER;
import static systems.uom.common.USCustomary.POUND;
import static systems.uom.common.USCustomary.HORSEPOWER;
import static systems.uom.common.USCustomary.ELECTRICAL_HORSEPOWER;
import static javax.measure.BinaryPrefix.*;
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.KILOGRAM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; | /*
* Units of Measurement Systems
* Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil and others.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385, Units of Measurement nor the names of their contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package systems.uom.common;
public class USTest {
@Test
public void testPound() { | // Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Length> METER = addUnit(METRE);
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Mass> POUND = addUnit(KILOGRAM.multiply(45359237).divide(100000000), "Pound", "lb"); // ,
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(745.69987158227), "Horsepower", "hp");
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> ELECTRICAL_HORSEPOWER = addUnit(WATT.multiply(746), "Horsepower (Electrical)", "hp(E)");
// Path: common/src/test/java/systems/uom/common/USTest.java
import static org.junit.jupiter.api.Assertions.assertNull;
import static systems.uom.common.USCustomary.METER;
import static systems.uom.common.USCustomary.POUND;
import static systems.uom.common.USCustomary.HORSEPOWER;
import static systems.uom.common.USCustomary.ELECTRICAL_HORSEPOWER;
import static javax.measure.BinaryPrefix.*;
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.KILOGRAM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*
* Units of Measurement Systems
* Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil and others.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385, Units of Measurement nor the names of their contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package systems.uom.common;
public class USTest {
@Test
public void testPound() { | assertEquals("lb", POUND.toString()); |
unitsofmeasurement/uom-systems | common/src/test/java/systems/uom/common/USTest.java | // Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Length> METER = addUnit(METRE);
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Mass> POUND = addUnit(KILOGRAM.multiply(45359237).divide(100000000), "Pound", "lb"); // ,
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(745.69987158227), "Horsepower", "hp");
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> ELECTRICAL_HORSEPOWER = addUnit(WATT.multiply(746), "Horsepower (Electrical)", "hp(E)");
| import static org.junit.jupiter.api.Assertions.assertNull;
import static systems.uom.common.USCustomary.METER;
import static systems.uom.common.USCustomary.POUND;
import static systems.uom.common.USCustomary.HORSEPOWER;
import static systems.uom.common.USCustomary.ELECTRICAL_HORSEPOWER;
import static javax.measure.BinaryPrefix.*;
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.KILOGRAM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; | /*
* Units of Measurement Systems
* Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil and others.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385, Units of Measurement nor the names of their contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package systems.uom.common;
public class USTest {
@Test
public void testPound() {
assertEquals("lb", POUND.toString());
assertEquals("klb", KILO(POUND).toString());
assertEquals("Kilb", KIBI(POUND).toString());
}
@Test
public void testHorsepower() { | // Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Length> METER = addUnit(METRE);
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Mass> POUND = addUnit(KILOGRAM.multiply(45359237).divide(100000000), "Pound", "lb"); // ,
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(745.69987158227), "Horsepower", "hp");
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> ELECTRICAL_HORSEPOWER = addUnit(WATT.multiply(746), "Horsepower (Electrical)", "hp(E)");
// Path: common/src/test/java/systems/uom/common/USTest.java
import static org.junit.jupiter.api.Assertions.assertNull;
import static systems.uom.common.USCustomary.METER;
import static systems.uom.common.USCustomary.POUND;
import static systems.uom.common.USCustomary.HORSEPOWER;
import static systems.uom.common.USCustomary.ELECTRICAL_HORSEPOWER;
import static javax.measure.BinaryPrefix.*;
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.KILOGRAM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*
* Units of Measurement Systems
* Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil and others.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385, Units of Measurement nor the names of their contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package systems.uom.common;
public class USTest {
@Test
public void testPound() {
assertEquals("lb", POUND.toString());
assertEquals("klb", KILO(POUND).toString());
assertEquals("Kilb", KIBI(POUND).toString());
}
@Test
public void testHorsepower() { | assertEquals("hp", HORSEPOWER.toString()); |
unitsofmeasurement/uom-systems | common/src/test/java/systems/uom/common/USTest.java | // Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Length> METER = addUnit(METRE);
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Mass> POUND = addUnit(KILOGRAM.multiply(45359237).divide(100000000), "Pound", "lb"); // ,
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(745.69987158227), "Horsepower", "hp");
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> ELECTRICAL_HORSEPOWER = addUnit(WATT.multiply(746), "Horsepower (Electrical)", "hp(E)");
| import static org.junit.jupiter.api.Assertions.assertNull;
import static systems.uom.common.USCustomary.METER;
import static systems.uom.common.USCustomary.POUND;
import static systems.uom.common.USCustomary.HORSEPOWER;
import static systems.uom.common.USCustomary.ELECTRICAL_HORSEPOWER;
import static javax.measure.BinaryPrefix.*;
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.KILOGRAM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; | /*
* Units of Measurement Systems
* Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil and others.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385, Units of Measurement nor the names of their contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package systems.uom.common;
public class USTest {
@Test
public void testPound() {
assertEquals("lb", POUND.toString());
assertEquals("klb", KILO(POUND).toString());
assertEquals("Kilb", KIBI(POUND).toString());
}
@Test
public void testHorsepower() {
assertEquals("hp", HORSEPOWER.toString());
}
@Test
public void testElectricalHorsepower() { | // Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Length> METER = addUnit(METRE);
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Mass> POUND = addUnit(KILOGRAM.multiply(45359237).divide(100000000), "Pound", "lb"); // ,
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(745.69987158227), "Horsepower", "hp");
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> ELECTRICAL_HORSEPOWER = addUnit(WATT.multiply(746), "Horsepower (Electrical)", "hp(E)");
// Path: common/src/test/java/systems/uom/common/USTest.java
import static org.junit.jupiter.api.Assertions.assertNull;
import static systems.uom.common.USCustomary.METER;
import static systems.uom.common.USCustomary.POUND;
import static systems.uom.common.USCustomary.HORSEPOWER;
import static systems.uom.common.USCustomary.ELECTRICAL_HORSEPOWER;
import static javax.measure.BinaryPrefix.*;
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.KILOGRAM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*
* Units of Measurement Systems
* Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil and others.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385, Units of Measurement nor the names of their contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package systems.uom.common;
public class USTest {
@Test
public void testPound() {
assertEquals("lb", POUND.toString());
assertEquals("klb", KILO(POUND).toString());
assertEquals("Kilb", KIBI(POUND).toString());
}
@Test
public void testHorsepower() {
assertEquals("hp", HORSEPOWER.toString());
}
@Test
public void testElectricalHorsepower() { | assertEquals("hp(E)", ELECTRICAL_HORSEPOWER.toString()); |
unitsofmeasurement/uom-systems | common/src/test/java/systems/uom/common/USTest.java | // Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Length> METER = addUnit(METRE);
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Mass> POUND = addUnit(KILOGRAM.multiply(45359237).divide(100000000), "Pound", "lb"); // ,
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(745.69987158227), "Horsepower", "hp");
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> ELECTRICAL_HORSEPOWER = addUnit(WATT.multiply(746), "Horsepower (Electrical)", "hp(E)");
| import static org.junit.jupiter.api.Assertions.assertNull;
import static systems.uom.common.USCustomary.METER;
import static systems.uom.common.USCustomary.POUND;
import static systems.uom.common.USCustomary.HORSEPOWER;
import static systems.uom.common.USCustomary.ELECTRICAL_HORSEPOWER;
import static javax.measure.BinaryPrefix.*;
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.KILOGRAM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; | /*
* Units of Measurement Systems
* Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil and others.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385, Units of Measurement nor the names of their contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package systems.uom.common;
public class USTest {
@Test
public void testPound() {
assertEquals("lb", POUND.toString());
assertEquals("klb", KILO(POUND).toString());
assertEquals("Kilb", KIBI(POUND).toString());
}
@Test
public void testHorsepower() {
assertEquals("hp", HORSEPOWER.toString());
}
@Test
public void testElectricalHorsepower() {
assertEquals("hp(E)", ELECTRICAL_HORSEPOWER.toString());
}
@Test
public void testMetreMeter() { | // Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Length> METER = addUnit(METRE);
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Mass> POUND = addUnit(KILOGRAM.multiply(45359237).divide(100000000), "Pound", "lb"); // ,
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> HORSEPOWER = addUnit(WATT.multiply(745.69987158227), "Horsepower", "hp");
//
// Path: common/src/main/java/systems/uom/common/USCustomary.java
// public static final Unit<Power> ELECTRICAL_HORSEPOWER = addUnit(WATT.multiply(746), "Horsepower (Electrical)", "hp(E)");
// Path: common/src/test/java/systems/uom/common/USTest.java
import static org.junit.jupiter.api.Assertions.assertNull;
import static systems.uom.common.USCustomary.METER;
import static systems.uom.common.USCustomary.POUND;
import static systems.uom.common.USCustomary.HORSEPOWER;
import static systems.uom.common.USCustomary.ELECTRICAL_HORSEPOWER;
import static javax.measure.BinaryPrefix.*;
import static javax.measure.MetricPrefix.*;
import static tech.units.indriya.unit.Units.METRE;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.KILOGRAM;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*
* Units of Measurement Systems
* Copyright (c) 2005-2021, Jean-Marie Dautelle, Werner Keil and others.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of JSR-385, Units of Measurement nor the names of their contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package systems.uom.common;
public class USTest {
@Test
public void testPound() {
assertEquals("lb", POUND.toString());
assertEquals("klb", KILO(POUND).toString());
assertEquals("Kilb", KIBI(POUND).toString());
}
@Test
public void testHorsepower() {
assertEquals("hp", HORSEPOWER.toString());
}
@Test
public void testElectricalHorsepower() {
assertEquals("hp(E)", ELECTRICAL_HORSEPOWER.toString());
}
@Test
public void testMetreMeter() { | assertEquals(METRE, METER); |
c00clupea/brew | app/src/edu/hm/muse/controller/WatchAccountController.java | // Path: app/src/edu/hm/muse/domain/User.java
// public class User {
// private int id;
//
// private String uname;
//
// private String upwd;
//
// public User() {
// }
//
// public User(int id, String uname, String upwd) {
// this.id = id;
// this.uname = uname;
// this.upwd = upwd;
// }
//
// public int getId() {
// return id;
// }
//
// public void setId(int id) {
// this.id = id;
// }
//
// public String getUname() {
// return uname;
// }
//
// public void setUname(String uname) {
// this.uname = uname;
// }
//
// public String getUpwd() {
// return upwd;
// }
//
// public void setUpwd(String upwd) {
// this.upwd = upwd;
// }
// }
| import edu.hm.muse.domain.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import java.security.MessageDigest;
import java.sql.Types; | /*
* **
* * __ ____ __
* * /'\_/`\ __ /\ \ /\ _`\ __/\ \__
* * /\ \ __ __ ___ /\_\ ___\ \ \___ \ \,\L\_\ __ ___ __ __ _ __ /\_\ \ ,_\ __ __
* * \ \ \__\ \/\ \/\ \/' _ `\/\ \ /'___\ \ _ `\ \/_\__ \ /'__`\ /'___\\ \/\ \/\`'__\/\ \ \ \/ /\ \/\ \
* * \ \ \_/\ \ \ \_\ \\ \/\ \ \ \/\ \__/\ \ \ \ \ /\ \L\ \/\ __//\ \__/ \ \_\ \ \ \/ \ \ \ \ \_\ \ \_\ \
* * \ \_\\ \_\ \____/ \_\ \_\ \_\ \____\\ \_\ \_\ \ `\____\ \____\ \____\ \____/\ \_\ \ \_\ \__\\/`____ \
* * \/_/ \/_/\/___/ \/_/\/_/\/_/\/____/ \/_/\/_/ \/_____/\/____/\/____/\/___/ \/_/ \/_/\/__/ `/___/> \
* * /\___/
* * \/__/
* *
* * ____ __ ____
* * /\ _`\ /\ \ /\ _`\
* * \ \ \L\ \ __ ____ __ __ _ __ ___\ \ \___ \ \ \L\_\ _ __ ___ __ __ _____
* * \ \ , / /'__`\ /',__\ /'__`\ /'__`\ /\`'__\'___\ \ _ `\ \ \ \L_L /\`'__\ __`\/\ \/\ \/\ '__`\
* * \ \ \\ \ /\ __//\__, `\\ __//\ \L\.\_\ \ \/\ \__/\ \ \ \ \ \ \ \/, \ \ \/\ \L\ \ \ \_\ \ \ \L\ \
* * \ \_\ \_\ \____\/\____/ \____\ \__/.\_\\ \_\ \____\\ \_\ \_\ \ \____/\ \_\ \____/\ \____/\ \ ,__/
* * \/_/\/ /\/____/\/___/ \/____/\/__/\/_/ \/_/\/____/ \/_/\/_/ \/___/ \/_/\/___/ \/___/ \ \ \/
* * \ \_\
* * This file is part of BREW.
* *
* * BREW 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.
* *
* * BREW 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 BREW. If not, see <http://www.gnu.org/licenses/>. \/_/
*
*/
package edu.hm.muse.controller;
@Controller
public class WatchAccountController {
private JdbcTemplate jdbcTemplate;
@Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@RequestMapping(value = "/internchange.secu", method = RequestMethod.GET)
public ModelAndView showAccountToChange(HttpSession session) {
if ((null == session) || (null == session.getAttribute("login")) || ((Boolean) session.getAttribute("login") == false)) {
return new ModelAndView("redirect:login.secu");
}
String uname = (String) session.getAttribute("user");
String sql = "select ID, muname,mpwd from M_USER where muname = ?";
| // Path: app/src/edu/hm/muse/domain/User.java
// public class User {
// private int id;
//
// private String uname;
//
// private String upwd;
//
// public User() {
// }
//
// public User(int id, String uname, String upwd) {
// this.id = id;
// this.uname = uname;
// this.upwd = upwd;
// }
//
// public int getId() {
// return id;
// }
//
// public void setId(int id) {
// this.id = id;
// }
//
// public String getUname() {
// return uname;
// }
//
// public void setUname(String uname) {
// this.uname = uname;
// }
//
// public String getUpwd() {
// return upwd;
// }
//
// public void setUpwd(String upwd) {
// this.upwd = upwd;
// }
// }
// Path: app/src/edu/hm/muse/controller/WatchAccountController.java
import edu.hm.muse.domain.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import java.security.MessageDigest;
import java.sql.Types;
/*
* **
* * __ ____ __
* * /'\_/`\ __ /\ \ /\ _`\ __/\ \__
* * /\ \ __ __ ___ /\_\ ___\ \ \___ \ \,\L\_\ __ ___ __ __ _ __ /\_\ \ ,_\ __ __
* * \ \ \__\ \/\ \/\ \/' _ `\/\ \ /'___\ \ _ `\ \/_\__ \ /'__`\ /'___\\ \/\ \/\`'__\/\ \ \ \/ /\ \/\ \
* * \ \ \_/\ \ \ \_\ \\ \/\ \ \ \/\ \__/\ \ \ \ \ /\ \L\ \/\ __//\ \__/ \ \_\ \ \ \/ \ \ \ \ \_\ \ \_\ \
* * \ \_\\ \_\ \____/ \_\ \_\ \_\ \____\\ \_\ \_\ \ `\____\ \____\ \____\ \____/\ \_\ \ \_\ \__\\/`____ \
* * \/_/ \/_/\/___/ \/_/\/_/\/_/\/____/ \/_/\/_/ \/_____/\/____/\/____/\/___/ \/_/ \/_/\/__/ `/___/> \
* * /\___/
* * \/__/
* *
* * ____ __ ____
* * /\ _`\ /\ \ /\ _`\
* * \ \ \L\ \ __ ____ __ __ _ __ ___\ \ \___ \ \ \L\_\ _ __ ___ __ __ _____
* * \ \ , / /'__`\ /',__\ /'__`\ /'__`\ /\`'__\'___\ \ _ `\ \ \ \L_L /\`'__\ __`\/\ \/\ \/\ '__`\
* * \ \ \\ \ /\ __//\__, `\\ __//\ \L\.\_\ \ \/\ \__/\ \ \ \ \ \ \ \/, \ \ \/\ \L\ \ \ \_\ \ \ \L\ \
* * \ \_\ \_\ \____\/\____/ \____\ \__/.\_\\ \_\ \____\\ \_\ \_\ \ \____/\ \_\ \____/\ \____/\ \ ,__/
* * \/_/\/ /\/____/\/___/ \/____/\/__/\/_/ \/_/\/____/ \/_/\/_/ \/___/ \/_/\/___/ \/___/ \ \ \/
* * \ \_\
* * This file is part of BREW.
* *
* * BREW 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.
* *
* * BREW 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 BREW. If not, see <http://www.gnu.org/licenses/>. \/_/
*
*/
package edu.hm.muse.controller;
@Controller
public class WatchAccountController {
private JdbcTemplate jdbcTemplate;
@Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@RequestMapping(value = "/internchange.secu", method = RequestMethod.GET)
public ModelAndView showAccountToChange(HttpSession session) {
if ((null == session) || (null == session.getAttribute("login")) || ((Boolean) session.getAttribute("login") == false)) {
return new ModelAndView("redirect:login.secu");
}
String uname = (String) session.getAttribute("user");
String sql = "select ID, muname,mpwd from M_USER where muname = ?";
| User u = jdbcTemplate.queryForObject(sql, new Object[]{uname}, new int[]{Types.VARCHAR}, new UserMapper()); |
c00clupea/brew | app/src/edu/hm/muse/controller/MailingListController.java | // Path: app/src/edu/hm/muse/domain/User.java
// public class User {
// private int id;
//
// private String uname;
//
// private String upwd;
//
// public User() {
// }
//
// public User(int id, String uname, String upwd) {
// this.id = id;
// this.uname = uname;
// this.upwd = upwd;
// }
//
// public int getId() {
// return id;
// }
//
// public void setId(int id) {
// this.id = id;
// }
//
// public String getUname() {
// return uname;
// }
//
// public void setUname(String uname) {
// this.uname = uname;
// }
//
// public String getUpwd() {
// return upwd;
// }
//
// public void setUpwd(String upwd) {
// this.upwd = upwd;
// }
// }
| import edu.hm.muse.domain.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.List; | /*
* **
* * __ ____ __
* * /'\_/`\ __ /\ \ /\ _`\ __/\ \__
* * /\ \ __ __ ___ /\_\ ___\ \ \___ \ \,\L\_\ __ ___ __ __ _ __ /\_\ \ ,_\ __ __
* * \ \ \__\ \/\ \/\ \/' _ `\/\ \ /'___\ \ _ `\ \/_\__ \ /'__`\ /'___\\ \/\ \/\`'__\/\ \ \ \/ /\ \/\ \
* * \ \ \_/\ \ \ \_\ \\ \/\ \ \ \/\ \__/\ \ \ \ \ /\ \L\ \/\ __//\ \__/ \ \_\ \ \ \/ \ \ \ \ \_\ \ \_\ \
* * \ \_\\ \_\ \____/ \_\ \_\ \_\ \____\\ \_\ \_\ \ `\____\ \____\ \____\ \____/\ \_\ \ \_\ \__\\/`____ \
* * \/_/ \/_/\/___/ \/_/\/_/\/_/\/____/ \/_/\/_/ \/_____/\/____/\/____/\/___/ \/_/ \/_/\/__/ `/___/> \
* * /\___/
* * \/__/
* *
* * ____ __ ____
* * /\ _`\ /\ \ /\ _`\
* * \ \ \L\ \ __ ____ __ __ _ __ ___\ \ \___ \ \ \L\_\ _ __ ___ __ __ _____
* * \ \ , / /'__`\ /',__\ /'__`\ /'__`\ /\`'__\'___\ \ _ `\ \ \ \L_L /\`'__\ __`\/\ \/\ \/\ '__`\
* * \ \ \\ \ /\ __//\__, `\\ __//\ \L\.\_\ \ \/\ \__/\ \ \ \ \ \ \ \/, \ \ \/\ \L\ \ \ \_\ \ \ \L\ \
* * \ \_\ \_\ \____\/\____/ \____\ \__/.\_\\ \_\ \____\\ \_\ \_\ \ \____/\ \_\ \____/\ \____/\ \ ,__/
* * \/_/\/ /\/____/\/___/ \/____/\/__/\/_/ \/_/\/____/ \/_/\/_/ \/___/ \/_/\/___/ \/___/ \ \ \/
* * \ \_\
* * This file is part of BREW.
* *
* * BREW 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.
* *
* * BREW 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 BREW. If not, see <http://www.gnu.org/licenses/>. \/_/
*
*/
package edu.hm.muse.controller;
@Controller
public class MailingListController {
private JdbcTemplate jdbcTemplate;
@Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@RequestMapping(value = "/mailing.secu")
public ModelAndView showAllMailings() {
String sql = "select * from M_USER";
| // Path: app/src/edu/hm/muse/domain/User.java
// public class User {
// private int id;
//
// private String uname;
//
// private String upwd;
//
// public User() {
// }
//
// public User(int id, String uname, String upwd) {
// this.id = id;
// this.uname = uname;
// this.upwd = upwd;
// }
//
// public int getId() {
// return id;
// }
//
// public void setId(int id) {
// this.id = id;
// }
//
// public String getUname() {
// return uname;
// }
//
// public void setUname(String uname) {
// this.uname = uname;
// }
//
// public String getUpwd() {
// return upwd;
// }
//
// public void setUpwd(String upwd) {
// this.upwd = upwd;
// }
// }
// Path: app/src/edu/hm/muse/controller/MailingListController.java
import edu.hm.muse.domain.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.List;
/*
* **
* * __ ____ __
* * /'\_/`\ __ /\ \ /\ _`\ __/\ \__
* * /\ \ __ __ ___ /\_\ ___\ \ \___ \ \,\L\_\ __ ___ __ __ _ __ /\_\ \ ,_\ __ __
* * \ \ \__\ \/\ \/\ \/' _ `\/\ \ /'___\ \ _ `\ \/_\__ \ /'__`\ /'___\\ \/\ \/\`'__\/\ \ \ \/ /\ \/\ \
* * \ \ \_/\ \ \ \_\ \\ \/\ \ \ \/\ \__/\ \ \ \ \ /\ \L\ \/\ __//\ \__/ \ \_\ \ \ \/ \ \ \ \ \_\ \ \_\ \
* * \ \_\\ \_\ \____/ \_\ \_\ \_\ \____\\ \_\ \_\ \ `\____\ \____\ \____\ \____/\ \_\ \ \_\ \__\\/`____ \
* * \/_/ \/_/\/___/ \/_/\/_/\/_/\/____/ \/_/\/_/ \/_____/\/____/\/____/\/___/ \/_/ \/_/\/__/ `/___/> \
* * /\___/
* * \/__/
* *
* * ____ __ ____
* * /\ _`\ /\ \ /\ _`\
* * \ \ \L\ \ __ ____ __ __ _ __ ___\ \ \___ \ \ \L\_\ _ __ ___ __ __ _____
* * \ \ , / /'__`\ /',__\ /'__`\ /'__`\ /\`'__\'___\ \ _ `\ \ \ \L_L /\`'__\ __`\/\ \/\ \/\ '__`\
* * \ \ \\ \ /\ __//\__, `\\ __//\ \L\.\_\ \ \/\ \__/\ \ \ \ \ \ \ \/, \ \ \/\ \L\ \ \ \_\ \ \ \L\ \
* * \ \_\ \_\ \____\/\____/ \____\ \__/.\_\\ \_\ \____\\ \_\ \_\ \ \____/\ \_\ \____/\ \____/\ \ ,__/
* * \/_/\/ /\/____/\/___/ \/____/\/__/\/_/ \/_/\/____/ \/_/\/_/ \/___/ \/_/\/___/ \/___/ \ \ \/
* * \ \_\
* * This file is part of BREW.
* *
* * BREW 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.
* *
* * BREW 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 BREW. If not, see <http://www.gnu.org/licenses/>. \/_/
*
*/
package edu.hm.muse.controller;
@Controller
public class MailingListController {
private JdbcTemplate jdbcTemplate;
@Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@RequestMapping(value = "/mailing.secu")
public ModelAndView showAllMailings() {
String sql = "select * from M_USER";
| List<User> users = jdbcTemplate.query(sql, new UserMapper()); |
c00clupea/brew | app/src/edu/hm/muse/controller/Logincontroller.java | // Path: app/src/edu/hm/muse/exception/SuperFatalAndReallyAnnoyingException.java
// public class SuperFatalAndReallyAnnoyingException extends RuntimeException {
// public SuperFatalAndReallyAnnoyingException(String msg) {
// super(msg);
// }
//
//
// }
| import edu.hm.muse.exception.SuperFatalAndReallyAnnoyingException;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.sql.Types; | /*
* **
* * __ ____ __
* * /'\_/`\ __ /\ \ /\ _`\ __/\ \__
* * /\ \ __ __ ___ /\_\ ___\ \ \___ \ \,\L\_\ __ ___ __ __ _ __ /\_\ \ ,_\ __ __
* * \ \ \__\ \/\ \/\ \/' _ `\/\ \ /'___\ \ _ `\ \/_\__ \ /'__`\ /'___\\ \/\ \/\`'__\/\ \ \ \/ /\ \/\ \
* * \ \ \_/\ \ \ \_\ \\ \/\ \ \ \/\ \__/\ \ \ \ \ /\ \L\ \/\ __//\ \__/ \ \_\ \ \ \/ \ \ \ \ \_\ \ \_\ \
* * \ \_\\ \_\ \____/ \_\ \_\ \_\ \____\\ \_\ \_\ \ `\____\ \____\ \____\ \____/\ \_\ \ \_\ \__\\/`____ \
* * \/_/ \/_/\/___/ \/_/\/_/\/_/\/____/ \/_/\/_/ \/_____/\/____/\/____/\/___/ \/_/ \/_/\/__/ `/___/> \
* * /\___/
* * \/__/
* *
* * ____ __ ____
* * /\ _`\ /\ \ /\ _`\
* * \ \ \L\ \ __ ____ __ __ _ __ ___\ \ \___ \ \ \L\_\ _ __ ___ __ __ _____
* * \ \ , / /'__`\ /',__\ /'__`\ /'__`\ /\`'__\'___\ \ _ `\ \ \ \L_L /\`'__\ __`\/\ \/\ \/\ '__`\
* * \ \ \\ \ /\ __//\__, `\\ __//\ \L\.\_\ \ \/\ \__/\ \ \ \ \ \ \ \/, \ \ \/\ \L\ \ \ \_\ \ \ \L\ \
* * \ \_\ \_\ \____\/\____/ \____\ \__/.\_\\ \_\ \____\\ \_\ \_\ \ \____/\ \_\ \____/\ \____/\ \ ,__/
* * \/_/\/ /\/____/\/___/ \/____/\/__/\/_/ \/_/\/____/ \/_/\/_/ \/___/ \/_/\/___/ \/___/ \ \ \/
* * \ \_\
* * This file is part of BREW.
* *
* * BREW 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.
* *
* * BREW 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 BREW. If not, see <http://www.gnu.org/licenses/>. \/_/
*
*/
package edu.hm.muse.controller;
@Controller
public class Logincontroller {
private JdbcTemplate jdbcTemplate;
@Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@RequestMapping(value = "/login.secu", method = RequestMethod.GET)
public ModelAndView showLoginScreen() {
ModelAndView mv = new ModelAndView("login");
mv.addObject("msg", "Enter name and password");
return mv;
}
@RequestMapping(value = "/adminlogin.secu", method = RequestMethod.GET)
public ModelAndView showAdminLoginScreen(HttpSession session) {
ModelAndView mv = new ModelAndView("adminlogin");
mv.addObject("msg", "Enter password");
SecureRandom random = new SecureRandom();
int token = random.nextInt();
mv.addObject("csrftoken",token);
session.setAttribute("csrftoken",token);
return mv;
}
@RequestMapping(value = "/login.secu", method = RequestMethod.POST)
public ModelAndView doSomeLogin(@RequestParam(value = "mname", required = false) String mname, @RequestParam(value = "mpwd", required = false) String mpwd, HttpSession session) {
if (null == mname || null == mpwd || mname.isEmpty() || mpwd.isEmpty()) { | // Path: app/src/edu/hm/muse/exception/SuperFatalAndReallyAnnoyingException.java
// public class SuperFatalAndReallyAnnoyingException extends RuntimeException {
// public SuperFatalAndReallyAnnoyingException(String msg) {
// super(msg);
// }
//
//
// }
// Path: app/src/edu/hm/muse/controller/Logincontroller.java
import edu.hm.muse.exception.SuperFatalAndReallyAnnoyingException;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.sql.Types;
/*
* **
* * __ ____ __
* * /'\_/`\ __ /\ \ /\ _`\ __/\ \__
* * /\ \ __ __ ___ /\_\ ___\ \ \___ \ \,\L\_\ __ ___ __ __ _ __ /\_\ \ ,_\ __ __
* * \ \ \__\ \/\ \/\ \/' _ `\/\ \ /'___\ \ _ `\ \/_\__ \ /'__`\ /'___\\ \/\ \/\`'__\/\ \ \ \/ /\ \/\ \
* * \ \ \_/\ \ \ \_\ \\ \/\ \ \ \/\ \__/\ \ \ \ \ /\ \L\ \/\ __//\ \__/ \ \_\ \ \ \/ \ \ \ \ \_\ \ \_\ \
* * \ \_\\ \_\ \____/ \_\ \_\ \_\ \____\\ \_\ \_\ \ `\____\ \____\ \____\ \____/\ \_\ \ \_\ \__\\/`____ \
* * \/_/ \/_/\/___/ \/_/\/_/\/_/\/____/ \/_/\/_/ \/_____/\/____/\/____/\/___/ \/_/ \/_/\/__/ `/___/> \
* * /\___/
* * \/__/
* *
* * ____ __ ____
* * /\ _`\ /\ \ /\ _`\
* * \ \ \L\ \ __ ____ __ __ _ __ ___\ \ \___ \ \ \L\_\ _ __ ___ __ __ _____
* * \ \ , / /'__`\ /',__\ /'__`\ /'__`\ /\`'__\'___\ \ _ `\ \ \ \L_L /\`'__\ __`\/\ \/\ \/\ '__`\
* * \ \ \\ \ /\ __//\__, `\\ __//\ \L\.\_\ \ \/\ \__/\ \ \ \ \ \ \ \/, \ \ \/\ \L\ \ \ \_\ \ \ \L\ \
* * \ \_\ \_\ \____\/\____/ \____\ \__/.\_\\ \_\ \____\\ \_\ \_\ \ \____/\ \_\ \____/\ \____/\ \ ,__/
* * \/_/\/ /\/____/\/___/ \/____/\/__/\/_/ \/_/\/____/ \/_/\/_/ \/___/ \/_/\/___/ \/___/ \ \ \/
* * \ \_\
* * This file is part of BREW.
* *
* * BREW 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.
* *
* * BREW 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 BREW. If not, see <http://www.gnu.org/licenses/>. \/_/
*
*/
package edu.hm.muse.controller;
@Controller
public class Logincontroller {
private JdbcTemplate jdbcTemplate;
@Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
@RequestMapping(value = "/login.secu", method = RequestMethod.GET)
public ModelAndView showLoginScreen() {
ModelAndView mv = new ModelAndView("login");
mv.addObject("msg", "Enter name and password");
return mv;
}
@RequestMapping(value = "/adminlogin.secu", method = RequestMethod.GET)
public ModelAndView showAdminLoginScreen(HttpSession session) {
ModelAndView mv = new ModelAndView("adminlogin");
mv.addObject("msg", "Enter password");
SecureRandom random = new SecureRandom();
int token = random.nextInt();
mv.addObject("csrftoken",token);
session.setAttribute("csrftoken",token);
return mv;
}
@RequestMapping(value = "/login.secu", method = RequestMethod.POST)
public ModelAndView doSomeLogin(@RequestParam(value = "mname", required = false) String mname, @RequestParam(value = "mpwd", required = false) String mpwd, HttpSession session) {
if (null == mname || null == mpwd || mname.isEmpty() || mpwd.isEmpty()) { | throw new SuperFatalAndReallyAnnoyingException("I can not process, because the requestparam mname or mpwd is empty or null or something like this"); |
landtanin/StudentAttendanceCheck | app/src/main/java/com/landtanin/studentattendancecheck/MainApplication.java | // Path: app/src/main/java/com/landtanin/studentattendancecheck/manager/Contextor.java
// public class Contextor {
//
// private static Contextor instance;
//
// public static Contextor getInstance() {
// if (instance == null)
// instance = new Contextor();
// return instance;
// }
//
// private Context mContext;
//
// private Contextor() {
//
// }
//
// public void init(Context context) {
// mContext = context;
// }
//
// public Context getContext() {
// return mContext;
// }
//
// }
| import android.app.Application;
import android.util.Log;
import com.crashlytics.android.Crashlytics;
import com.landtanin.studentattendancecheck.manager.Contextor;
import io.fabric.sdk.android.Fabric;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.exceptions.RealmMigrationNeededException;
import io.realm.rx.RealmObservableFactory; | package com.landtanin.studentattendancecheck;
/**
* Created by landtanin on 2/11/2017 AD.
*/
public class MainApplication extends Application {
RealmConfiguration config;
private final String DATABASE_NAME="landtanin.realm";
@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
| // Path: app/src/main/java/com/landtanin/studentattendancecheck/manager/Contextor.java
// public class Contextor {
//
// private static Contextor instance;
//
// public static Contextor getInstance() {
// if (instance == null)
// instance = new Contextor();
// return instance;
// }
//
// private Context mContext;
//
// private Contextor() {
//
// }
//
// public void init(Context context) {
// mContext = context;
// }
//
// public Context getContext() {
// return mContext;
// }
//
// }
// Path: app/src/main/java/com/landtanin/studentattendancecheck/MainApplication.java
import android.app.Application;
import android.util.Log;
import com.crashlytics.android.Crashlytics;
import com.landtanin.studentattendancecheck.manager.Contextor;
import io.fabric.sdk.android.Fabric;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.exceptions.RealmMigrationNeededException;
import io.realm.rx.RealmObservableFactory;
package com.landtanin.studentattendancecheck;
/**
* Created by landtanin on 2/11/2017 AD.
*/
public class MainApplication extends Application {
RealmConfiguration config;
private final String DATABASE_NAME="landtanin.realm";
@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
| Contextor.getInstance().init(getApplicationContext()); |
landtanin/StudentAttendanceCheck | app/src/main/java/com/landtanin/studentattendancecheck/fragment/MainFragment.java | // Path: app/src/main/java/com/landtanin/studentattendancecheck/activity/AddModuleActivity.java
// public class AddModuleActivity extends AppCompatActivity {
//
// // ActivityAddModuleBinding b;
// ActivityAddModuleBinding b;
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// b = DataBindingUtil.setContentView(this, R.layout.activity_add_module);
//
// initInstance();
//
// if (savedInstanceState == null) {
//
// getSupportFragmentManager().beginTransaction()
// .add(R.id.addModuleFragmentContentContainer,
// FragmentAddModule.newInstance(),
// "AddModuleFragment")
// .commit();
//
// }
//
// }
//
// private void initInstance() {
//
// // **** toolbar
// setSupportActionBar(b.addModuleActivityToolbar);
//
// // **** done button
// b.btnDoneAddModule.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
//
// Intent returnIntent = new Intent();
// returnIntent.putExtra("result", "test");
// setResult(RESULT_OK, returnIntent);
//
// finish();
//
// // TODO: Save selected item into local database
//
// }
// });
//
// }
//
// }
| import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import com.landtanin.studentattendancecheck.R;
import com.landtanin.studentattendancecheck.activity.AddModuleActivity;
import com.landtanin.studentattendancecheck.databinding.FragmentMainBinding;
import static android.app.Activity.RESULT_OK; |
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init(savedInstanceState);
if (savedInstanceState != null)
onRestoreInstanceState(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
b = DataBindingUtil.inflate(inflater, R.layout.fragment_main, container, false);
View rootView = b.getRoot();
initInstances(rootView);
return rootView;
}
@SuppressWarnings("UnusedParameters")
private void init(Bundle savedInstanceState) {
// Init Fragment level's variable(s) here
}
private void initInstances(View rootView) {
// Init 'View' instance(s) with rootView.findViewById here
b.plusSignImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
| // Path: app/src/main/java/com/landtanin/studentattendancecheck/activity/AddModuleActivity.java
// public class AddModuleActivity extends AppCompatActivity {
//
// // ActivityAddModuleBinding b;
// ActivityAddModuleBinding b;
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// b = DataBindingUtil.setContentView(this, R.layout.activity_add_module);
//
// initInstance();
//
// if (savedInstanceState == null) {
//
// getSupportFragmentManager().beginTransaction()
// .add(R.id.addModuleFragmentContentContainer,
// FragmentAddModule.newInstance(),
// "AddModuleFragment")
// .commit();
//
// }
//
// }
//
// private void initInstance() {
//
// // **** toolbar
// setSupportActionBar(b.addModuleActivityToolbar);
//
// // **** done button
// b.btnDoneAddModule.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
//
// Intent returnIntent = new Intent();
// returnIntent.putExtra("result", "test");
// setResult(RESULT_OK, returnIntent);
//
// finish();
//
// // TODO: Save selected item into local database
//
// }
// });
//
// }
//
// }
// Path: app/src/main/java/com/landtanin/studentattendancecheck/fragment/MainFragment.java
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import com.landtanin.studentattendancecheck.R;
import com.landtanin.studentattendancecheck.activity.AddModuleActivity;
import com.landtanin.studentattendancecheck.databinding.FragmentMainBinding;
import static android.app.Activity.RESULT_OK;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init(savedInstanceState);
if (savedInstanceState != null)
onRestoreInstanceState(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
b = DataBindingUtil.inflate(inflater, R.layout.fragment_main, container, false);
View rootView = b.getRoot();
initInstances(rootView);
return rootView;
}
@SuppressWarnings("UnusedParameters")
private void init(Bundle savedInstanceState) {
// Init Fragment level's variable(s) here
}
private void initInstances(View rootView) {
// Init 'View' instance(s) with rootView.findViewById here
b.plusSignImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
| Intent objIntent = new Intent(getContext(), AddModuleActivity.class); |
landtanin/StudentAttendanceCheck | app/src/main/java/com/landtanin/studentattendancecheck/fragment/FragmentAddModule.java | // Path: app/src/main/java/com/landtanin/studentattendancecheck/adapter/AddModuleAdapter.java
// public class AddModuleAdapter extends RecyclerView.Adapter<AddModuleAdapter.RecyclerViewHolder> {
//
// private List<AddModuleItem> mModuleItemList;
// Context mContext;
//
//
//
//
// public AddModuleAdapter(List<AddModuleItem> moduleItemList, Context context) {
// mModuleItemList = moduleItemList;
// mContext = context;
// }
//
// @Override
// public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_add_module, parent, false);
// return new RecyclerViewHolder(itemView);
// }
//
// @Override
// public void onBindViewHolder(RecyclerViewHolder holder, int position) {
//
// AddModuleItem addModuleItem = mModuleItemList.get(position);
//
// holder.addModuleModuleNameTxt.setText(addModuleItem.getModuleText());
// holder.addModuleModuleIdTxt.setText(addModuleItem.getModuleId());
// holder.addModuleCheckBox.setChecked(false);
//
// }
//
// @Override
// public int getItemCount() {
// return 100;
// }
//
// public class RecyclerViewHolder extends RecyclerView.ViewHolder{
//
// TextView addModuleModuleNameTxt;
// TextView addModuleModuleIdTxt;
// CheckBox addModuleCheckBox;
//
// public RecyclerViewHolder(View itemView) {
// super(itemView);
//
// addModuleModuleNameTxt = (TextView) itemView.findViewById(R.id.addModuleModuleNameTxt);
// addModuleModuleIdTxt = (TextView) itemView.findViewById(R.id.addModuleModuleIdTxt);
// addModuleCheckBox = (CheckBox) itemView.findViewById(R.id.addModuleCheckbox);
//
// }
// }
// }
//
// Path: app/src/main/java/com/landtanin/studentattendancecheck/adapter/AddModuleItem.java
// public class AddModuleItem {
//
// public String moduleText;
// public String moduleId;
// public boolean checkboxStatus;
//
// public AddModuleItem(String moduleText, String moduleId, boolean checkboxStatus) {
// this.moduleText = moduleText;
// this.moduleId = moduleId;
// this.checkboxStatus = checkboxStatus;
// }
//
//
//
// public String getModuleText() {
// return moduleText;
// }
//
// public void setModuleText(String moduleText) {
// this.moduleText = moduleText;
// }
//
// public String getModuleId() {
// return moduleId;
// }
//
// public void setModuleId(String moduleId) {
// this.moduleId = moduleId;
// }
//
// public boolean isCheckboxStatus() {
// return checkboxStatus;
// }
//
// public void setCheckboxStatus(boolean checkboxStatus) {
// this.checkboxStatus = checkboxStatus;
// }
// }
| import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.landtanin.studentattendancecheck.R;
import com.landtanin.studentattendancecheck.adapter.AddModuleAdapter;
import com.landtanin.studentattendancecheck.adapter.AddModuleItem;
import com.landtanin.studentattendancecheck.databinding.FragmentAddModuleBinding;
import java.util.ArrayList;
import java.util.List; | package com.landtanin.studentattendancecheck.fragment;
/**
* Created by nuuneoi on 11/16/2014.
*/
public class FragmentAddModule extends Fragment {
AddModuleAdapter mAddModuleAdapter; | // Path: app/src/main/java/com/landtanin/studentattendancecheck/adapter/AddModuleAdapter.java
// public class AddModuleAdapter extends RecyclerView.Adapter<AddModuleAdapter.RecyclerViewHolder> {
//
// private List<AddModuleItem> mModuleItemList;
// Context mContext;
//
//
//
//
// public AddModuleAdapter(List<AddModuleItem> moduleItemList, Context context) {
// mModuleItemList = moduleItemList;
// mContext = context;
// }
//
// @Override
// public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_add_module, parent, false);
// return new RecyclerViewHolder(itemView);
// }
//
// @Override
// public void onBindViewHolder(RecyclerViewHolder holder, int position) {
//
// AddModuleItem addModuleItem = mModuleItemList.get(position);
//
// holder.addModuleModuleNameTxt.setText(addModuleItem.getModuleText());
// holder.addModuleModuleIdTxt.setText(addModuleItem.getModuleId());
// holder.addModuleCheckBox.setChecked(false);
//
// }
//
// @Override
// public int getItemCount() {
// return 100;
// }
//
// public class RecyclerViewHolder extends RecyclerView.ViewHolder{
//
// TextView addModuleModuleNameTxt;
// TextView addModuleModuleIdTxt;
// CheckBox addModuleCheckBox;
//
// public RecyclerViewHolder(View itemView) {
// super(itemView);
//
// addModuleModuleNameTxt = (TextView) itemView.findViewById(R.id.addModuleModuleNameTxt);
// addModuleModuleIdTxt = (TextView) itemView.findViewById(R.id.addModuleModuleIdTxt);
// addModuleCheckBox = (CheckBox) itemView.findViewById(R.id.addModuleCheckbox);
//
// }
// }
// }
//
// Path: app/src/main/java/com/landtanin/studentattendancecheck/adapter/AddModuleItem.java
// public class AddModuleItem {
//
// public String moduleText;
// public String moduleId;
// public boolean checkboxStatus;
//
// public AddModuleItem(String moduleText, String moduleId, boolean checkboxStatus) {
// this.moduleText = moduleText;
// this.moduleId = moduleId;
// this.checkboxStatus = checkboxStatus;
// }
//
//
//
// public String getModuleText() {
// return moduleText;
// }
//
// public void setModuleText(String moduleText) {
// this.moduleText = moduleText;
// }
//
// public String getModuleId() {
// return moduleId;
// }
//
// public void setModuleId(String moduleId) {
// this.moduleId = moduleId;
// }
//
// public boolean isCheckboxStatus() {
// return checkboxStatus;
// }
//
// public void setCheckboxStatus(boolean checkboxStatus) {
// this.checkboxStatus = checkboxStatus;
// }
// }
// Path: app/src/main/java/com/landtanin/studentattendancecheck/fragment/FragmentAddModule.java
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.landtanin.studentattendancecheck.R;
import com.landtanin.studentattendancecheck.adapter.AddModuleAdapter;
import com.landtanin.studentattendancecheck.adapter.AddModuleItem;
import com.landtanin.studentattendancecheck.databinding.FragmentAddModuleBinding;
import java.util.ArrayList;
import java.util.List;
package com.landtanin.studentattendancecheck.fragment;
/**
* Created by nuuneoi on 11/16/2014.
*/
public class FragmentAddModule extends Fragment {
AddModuleAdapter mAddModuleAdapter; | List<AddModuleItem> mModuleItemList = new ArrayList<>(); |
landtanin/StudentAttendanceCheck | app/src/main/java/com/landtanin/studentattendancecheck/fragment/FragmentHome.java | // Path: app/src/main/java/com/landtanin/studentattendancecheck/manager/SmartFragmentStatePagerAdapter.java
// public class SmartFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
//
// private SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
//
// public SmartFragmentStatePagerAdapter(FragmentManager fm) {
// super(fm);
// }
//
// @Override
// public Fragment getItem(int position) {
// return null;
// }
//
// @Override
// public int getCount() {
// return 0;
// }
//
// // Register the fragment when the item is instantiated
// @Override
// public Object instantiateItem(ViewGroup container, int position) {
// Fragment fragment = (Fragment) super.instantiateItem(container, position);
// registeredFragments.put(position, fragment);
// return fragment;
// }
//
// // Unregister when the item is inactive
// @Override
// public void destroyItem(ViewGroup container, int position, Object object) {
// registeredFragments.remove(position);
// super.destroyItem(container, position, object);
// }
//
// // Returns the fragment for the position (if instantiated)
// public Fragment getRegisteredFragment(int position) {
// return registeredFragments.get(position);
// }
// }
| import android.content.DialogInterface;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.landtanin.studentattendancecheck.R;
import com.landtanin.studentattendancecheck.databinding.FragmentHomeBinding;
import com.landtanin.studentattendancecheck.manager.SmartFragmentStatePagerAdapter; | b.fragHomeTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save Instance (Fragment level's variables) State here
}
@SuppressWarnings("UnusedParameters")
private void onRestoreInstanceState(Bundle savedInstanceState) {
// Restore Instance (Fragment level's variables) State here
}
| // Path: app/src/main/java/com/landtanin/studentattendancecheck/manager/SmartFragmentStatePagerAdapter.java
// public class SmartFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
//
// private SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
//
// public SmartFragmentStatePagerAdapter(FragmentManager fm) {
// super(fm);
// }
//
// @Override
// public Fragment getItem(int position) {
// return null;
// }
//
// @Override
// public int getCount() {
// return 0;
// }
//
// // Register the fragment when the item is instantiated
// @Override
// public Object instantiateItem(ViewGroup container, int position) {
// Fragment fragment = (Fragment) super.instantiateItem(container, position);
// registeredFragments.put(position, fragment);
// return fragment;
// }
//
// // Unregister when the item is inactive
// @Override
// public void destroyItem(ViewGroup container, int position, Object object) {
// registeredFragments.remove(position);
// super.destroyItem(container, position, object);
// }
//
// // Returns the fragment for the position (if instantiated)
// public Fragment getRegisteredFragment(int position) {
// return registeredFragments.get(position);
// }
// }
// Path: app/src/main/java/com/landtanin/studentattendancecheck/fragment/FragmentHome.java
import android.content.DialogInterface;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.landtanin.studentattendancecheck.R;
import com.landtanin.studentattendancecheck.databinding.FragmentHomeBinding;
import com.landtanin.studentattendancecheck.manager.SmartFragmentStatePagerAdapter;
b.fragHomeTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save Instance (Fragment level's variables) State here
}
@SuppressWarnings("UnusedParameters")
private void onRestoreInstanceState(Bundle savedInstanceState) {
// Restore Instance (Fragment level's variables) State here
}
| public class FragmentHomePagerAdapter extends SmartFragmentStatePagerAdapter { |
landtanin/StudentAttendanceCheck | app/src/main/java/com/landtanin/studentattendancecheck/activity/AddModuleActivity.java | // Path: app/src/main/java/com/landtanin/studentattendancecheck/fragment/FragmentAddModule.java
// public class FragmentAddModule extends Fragment {
//
// AddModuleAdapter mAddModuleAdapter;
// List<AddModuleItem> mModuleItemList = new ArrayList<>();
// FragmentAddModuleBinding b;
//
// public FragmentAddModule() {
// super();
// }
//
// public static FragmentAddModule newInstance() {
// FragmentAddModule fragment = new FragmentAddModule();
// Bundle args = new Bundle();
// fragment.setArguments(args);
// return fragment;
// }
//
// @Override
// public void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// init(savedInstanceState);
//
// if (savedInstanceState != null)
// onRestoreInstanceState(savedInstanceState);
// }
//
// @Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
// b = DataBindingUtil.inflate(inflater, R.layout.fragment_add_module, container, false);
// View rootView = b.getRoot();
// initInstances(rootView, savedInstanceState);
// return rootView;
// }
//
// @SuppressWarnings("UnusedParameters")
// private void init(Bundle savedInstanceState) {
// // Init Fragment level's variable(s) here
// }
//
// @SuppressWarnings("UnusedParameters")
// private void initInstances(View rootView, Bundle savedInstanceState) {
// // Init 'View' instance(s) with rootView.findViewById here
// // Note: State of variable initialized here could not be saved
// // in onSavedInstanceState
// StaggeredGridLayoutManager rvLayoutManager = new StaggeredGridLayoutManager(1, 1);
// b.rvAddModule.setLayoutManager(rvLayoutManager);
// mAddModuleAdapter = new AddModuleAdapter(mModuleItemList, getContext());
//
// b.rvAddModule.setAdapter(mAddModuleAdapter);
// b.rvAddModule.setHasFixedSize(true);
//
// connectToDataBase();
//
// }
//
// private void connectToDataBase() {
//
// // hardcoded item to RecyclerView
// for (int i = 0; i < 100; i++) {
//
// AddModuleItem addModuleItem = new AddModuleItem("item " + i, "item2 " + i, false);
// mModuleItemList.add(addModuleItem);
//
// }
//
// mAddModuleAdapter.notifyDataSetChanged();
//
// }
//
//
//
// @Override
// public void onSaveInstanceState(Bundle outState) {
// super.onSaveInstanceState(outState);
// // Save Instance (Fragment level's variables) State here
// }
//
// @SuppressWarnings("UnusedParameters")
// private void onRestoreInstanceState(Bundle savedInstanceState) {
// // Restore Instance (Fragment level's variables) State here
// }
//
// }
| import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.landtanin.studentattendancecheck.R;
import com.landtanin.studentattendancecheck.databinding.ActivityAddModuleBinding;
import com.landtanin.studentattendancecheck.fragment.FragmentAddModule; | package com.landtanin.studentattendancecheck.activity;
public class AddModuleActivity extends AppCompatActivity {
// ActivityAddModuleBinding b;
ActivityAddModuleBinding b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
b = DataBindingUtil.setContentView(this, R.layout.activity_add_module);
initInstance();
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.addModuleFragmentContentContainer, | // Path: app/src/main/java/com/landtanin/studentattendancecheck/fragment/FragmentAddModule.java
// public class FragmentAddModule extends Fragment {
//
// AddModuleAdapter mAddModuleAdapter;
// List<AddModuleItem> mModuleItemList = new ArrayList<>();
// FragmentAddModuleBinding b;
//
// public FragmentAddModule() {
// super();
// }
//
// public static FragmentAddModule newInstance() {
// FragmentAddModule fragment = new FragmentAddModule();
// Bundle args = new Bundle();
// fragment.setArguments(args);
// return fragment;
// }
//
// @Override
// public void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// init(savedInstanceState);
//
// if (savedInstanceState != null)
// onRestoreInstanceState(savedInstanceState);
// }
//
// @Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
// b = DataBindingUtil.inflate(inflater, R.layout.fragment_add_module, container, false);
// View rootView = b.getRoot();
// initInstances(rootView, savedInstanceState);
// return rootView;
// }
//
// @SuppressWarnings("UnusedParameters")
// private void init(Bundle savedInstanceState) {
// // Init Fragment level's variable(s) here
// }
//
// @SuppressWarnings("UnusedParameters")
// private void initInstances(View rootView, Bundle savedInstanceState) {
// // Init 'View' instance(s) with rootView.findViewById here
// // Note: State of variable initialized here could not be saved
// // in onSavedInstanceState
// StaggeredGridLayoutManager rvLayoutManager = new StaggeredGridLayoutManager(1, 1);
// b.rvAddModule.setLayoutManager(rvLayoutManager);
// mAddModuleAdapter = new AddModuleAdapter(mModuleItemList, getContext());
//
// b.rvAddModule.setAdapter(mAddModuleAdapter);
// b.rvAddModule.setHasFixedSize(true);
//
// connectToDataBase();
//
// }
//
// private void connectToDataBase() {
//
// // hardcoded item to RecyclerView
// for (int i = 0; i < 100; i++) {
//
// AddModuleItem addModuleItem = new AddModuleItem("item " + i, "item2 " + i, false);
// mModuleItemList.add(addModuleItem);
//
// }
//
// mAddModuleAdapter.notifyDataSetChanged();
//
// }
//
//
//
// @Override
// public void onSaveInstanceState(Bundle outState) {
// super.onSaveInstanceState(outState);
// // Save Instance (Fragment level's variables) State here
// }
//
// @SuppressWarnings("UnusedParameters")
// private void onRestoreInstanceState(Bundle savedInstanceState) {
// // Restore Instance (Fragment level's variables) State here
// }
//
// }
// Path: app/src/main/java/com/landtanin/studentattendancecheck/activity/AddModuleActivity.java
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.landtanin.studentattendancecheck.R;
import com.landtanin.studentattendancecheck.databinding.ActivityAddModuleBinding;
import com.landtanin.studentattendancecheck.fragment.FragmentAddModule;
package com.landtanin.studentattendancecheck.activity;
public class AddModuleActivity extends AppCompatActivity {
// ActivityAddModuleBinding b;
ActivityAddModuleBinding b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
b = DataBindingUtil.setContentView(this, R.layout.activity_add_module);
initInstance();
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.addModuleFragmentContentContainer, | FragmentAddModule.newInstance(), |
landtanin/StudentAttendanceCheck | app/src/main/java/com/landtanin/studentattendancecheck/manager/TodayModule.java | // Path: app/src/main/java/com/landtanin/studentattendancecheck/dao/StudentModuleDao.java
// public class StudentModuleDao extends RealmObject implements RealmModel{
// @PrimaryKey
// @SerializedName("_id")
// @Expose
// private String id;
// @SerializedName("name")
// @Expose
// private String name;
// @SerializedName("moduleId")
// @Expose
// private String moduleId;
// @SerializedName("startDate")
// @Expose
// private Date startDate;
// @SerializedName("endDate")
// @Expose
// private Date endDate;
// @SerializedName("checkInStart")
// @Expose
// private Date checkInStart;
// @SerializedName("checkInEnd")
// @Expose
// private Date checkInEnd;
// @SerializedName("room")
// @Expose
// private String room;
// @SerializedName("LocLat")
// @Expose
// private double locLat;
// @SerializedName("LocLng")
// @Expose
// private double locLng;
// @SerializedName("ModStatus")
// @Expose
// private String modStatus;
// @SerializedName("Day")
// @Expose
// private String day;
// @SerializedName("Lecturer")
// @Expose
// private String lecturer;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getModuleId() {
// return moduleId;
// }
//
// public void setModuleId(String moduleId) {
// this.moduleId = moduleId;
// }
//
// public Date getStartDate() {
// return startDate;
// }
//
// public void setStartDate(Date startDate) {
// this.startDate = startDate;
// }
//
// public Date getEndDate() {
// return endDate;
// }
//
// public void setEndDate(Date endDate) {
// this.endDate = endDate;
// }
//
// public Date getCheckInStart() {
// return checkInStart;
// }
//
// public void setCheckInStart(Date checkInStart) {
// this.checkInStart = checkInStart;
// }
//
// public Date getCheckInEnd() {
// return checkInEnd;
// }
//
// public void setCheckInEnd(Date checkInEnd) {
// this.checkInEnd = checkInEnd;
// }
//
// public String getRoom() {
// return room;
// }
//
// public void setRoom(String room) {
// this.room = room;
// }
//
// public double getLocLat() {
// return locLat;
// }
//
// public void setLocLat(double locLat) {
// this.locLat = locLat;
// }
//
// public double getLocLng() {
// return locLng;
// }
//
// public void setLocLng(double locLng) {
// this.locLng = locLng;
// }
//
// public String getModStatus() {
// return modStatus;
// }
//
// public void setModStatus(String modStatus) {
// this.modStatus = modStatus;
// }
//
// public String getDay() {
// return day;
// }
//
// public void setDay(String day) {
// this.day = day;
// }
//
// public String getLecturer() {
// return lecturer;
// }
//
// public void setLecturer(String lecturer) {
// this.lecturer = lecturer;
// }
// }
| import android.content.Context;
import com.landtanin.studentattendancecheck.dao.StudentModuleDao;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmResults; | package com.landtanin.studentattendancecheck.manager;
/**
* Created by landtanin on 4/15/2017 AD.
*/
public class TodayModule {
private static TodayModule instance;
public static TodayModule getInstance() {
if (instance == null) {
instance = new TodayModule();
}
return instance;
}
private Context mContext;
private TodayModule() {
mContext = Contextor.getInstance().getContext();
}
| // Path: app/src/main/java/com/landtanin/studentattendancecheck/dao/StudentModuleDao.java
// public class StudentModuleDao extends RealmObject implements RealmModel{
// @PrimaryKey
// @SerializedName("_id")
// @Expose
// private String id;
// @SerializedName("name")
// @Expose
// private String name;
// @SerializedName("moduleId")
// @Expose
// private String moduleId;
// @SerializedName("startDate")
// @Expose
// private Date startDate;
// @SerializedName("endDate")
// @Expose
// private Date endDate;
// @SerializedName("checkInStart")
// @Expose
// private Date checkInStart;
// @SerializedName("checkInEnd")
// @Expose
// private Date checkInEnd;
// @SerializedName("room")
// @Expose
// private String room;
// @SerializedName("LocLat")
// @Expose
// private double locLat;
// @SerializedName("LocLng")
// @Expose
// private double locLng;
// @SerializedName("ModStatus")
// @Expose
// private String modStatus;
// @SerializedName("Day")
// @Expose
// private String day;
// @SerializedName("Lecturer")
// @Expose
// private String lecturer;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getModuleId() {
// return moduleId;
// }
//
// public void setModuleId(String moduleId) {
// this.moduleId = moduleId;
// }
//
// public Date getStartDate() {
// return startDate;
// }
//
// public void setStartDate(Date startDate) {
// this.startDate = startDate;
// }
//
// public Date getEndDate() {
// return endDate;
// }
//
// public void setEndDate(Date endDate) {
// this.endDate = endDate;
// }
//
// public Date getCheckInStart() {
// return checkInStart;
// }
//
// public void setCheckInStart(Date checkInStart) {
// this.checkInStart = checkInStart;
// }
//
// public Date getCheckInEnd() {
// return checkInEnd;
// }
//
// public void setCheckInEnd(Date checkInEnd) {
// this.checkInEnd = checkInEnd;
// }
//
// public String getRoom() {
// return room;
// }
//
// public void setRoom(String room) {
// this.room = room;
// }
//
// public double getLocLat() {
// return locLat;
// }
//
// public void setLocLat(double locLat) {
// this.locLat = locLat;
// }
//
// public double getLocLng() {
// return locLng;
// }
//
// public void setLocLng(double locLng) {
// this.locLng = locLng;
// }
//
// public String getModStatus() {
// return modStatus;
// }
//
// public void setModStatus(String modStatus) {
// this.modStatus = modStatus;
// }
//
// public String getDay() {
// return day;
// }
//
// public void setDay(String day) {
// this.day = day;
// }
//
// public String getLecturer() {
// return lecturer;
// }
//
// public void setLecturer(String lecturer) {
// this.lecturer = lecturer;
// }
// }
// Path: app/src/main/java/com/landtanin/studentattendancecheck/manager/TodayModule.java
import android.content.Context;
import com.landtanin.studentattendancecheck.dao.StudentModuleDao;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmResults;
package com.landtanin.studentattendancecheck.manager;
/**
* Created by landtanin on 4/15/2017 AD.
*/
public class TodayModule {
private static TodayModule instance;
public static TodayModule getInstance() {
if (instance == null) {
instance = new TodayModule();
}
return instance;
}
private Context mContext;
private TodayModule() {
mContext = Contextor.getInstance().getContext();
}
| public RealmResults<StudentModuleDao> getTodayModule() { |
landtanin/StudentAttendanceCheck | app/src/main/java/com/landtanin/studentattendancecheck/util/Utils.java | // Path: app/src/main/java/com/landtanin/studentattendancecheck/manager/Contextor.java
// public class Contextor {
//
// private static Contextor instance;
//
// public static Contextor getInstance() {
// if (instance == null)
// instance = new Contextor();
// return instance;
// }
//
// private Context mContext;
//
// private Contextor() {
//
// }
//
// public void init(Context context) {
// mContext = context;
// }
//
// public Context getContext() {
// return mContext;
// }
//
// }
| import android.content.Context;
import android.widget.Toast;
import com.landtanin.studentattendancecheck.manager.Contextor;
import rx.Scheduler;
import rx.schedulers.Schedulers; | package com.landtanin.studentattendancecheck.util;
/**
* Created by landtanin on 4/11/2017 AD.
*/
public class Utils {
private static Utils ourInstance;
private Context mContext;
private Scheduler defaultSubscribeScheduler;
private Utils() { | // Path: app/src/main/java/com/landtanin/studentattendancecheck/manager/Contextor.java
// public class Contextor {
//
// private static Contextor instance;
//
// public static Contextor getInstance() {
// if (instance == null)
// instance = new Contextor();
// return instance;
// }
//
// private Context mContext;
//
// private Contextor() {
//
// }
//
// public void init(Context context) {
// mContext = context;
// }
//
// public Context getContext() {
// return mContext;
// }
//
// }
// Path: app/src/main/java/com/landtanin/studentattendancecheck/util/Utils.java
import android.content.Context;
import android.widget.Toast;
import com.landtanin.studentattendancecheck.manager.Contextor;
import rx.Scheduler;
import rx.schedulers.Schedulers;
package com.landtanin.studentattendancecheck.util;
/**
* Created by landtanin on 4/11/2017 AD.
*/
public class Utils {
private static Utils ourInstance;
private Context mContext;
private Scheduler defaultSubscribeScheduler;
private Utils() { | mContext = Contextor.getInstance().getContext(); |
landtanin/StudentAttendanceCheck | app/src/main/java/com/landtanin/studentattendancecheck/manager/http/ApiService.java | // Path: app/src/main/java/com/landtanin/studentattendancecheck/dao/StudentModuleCollectionDao.java
// public class StudentModuleCollectionDao{
//
// @SerializedName("modules")
// @Expose
// private List<StudentModuleDao> data = null;
//
// public List<StudentModuleDao> getData() {
// return data;
// }
//
// public void setData(List<StudentModuleDao> data) {
// this.data = data;
// }
//
// @SerializedName("result")
// @Expose
// private String result;
// @SerializedName("message")
// @Expose
// private String message;
// @SerializedName("user")
// @Expose
// private User user;
//
// public String getResult() {
// return result;
// }
//
// public void setResult(String result) {
// this.result = result;
// }
//
// public String getMessage() {
// return message;
// }
//
// public void setMessage(String message) {
// this.message = message;
// }
//
// public User getUser() {
// return user;
// }
//
// public void setUser(User user) {
// this.user = user;
// }
//
// }
| import com.landtanin.studentattendancecheck.dao.StudentModuleCollectionDao;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
import rx.Observable; | package com.landtanin.studentattendancecheck.manager.http;
/**
* Created by landtanin on 4/10/2017 AD.
*/
public interface ApiService {
@FormUrlEncoded
@POST("studentLogin/index.php") | // Path: app/src/main/java/com/landtanin/studentattendancecheck/dao/StudentModuleCollectionDao.java
// public class StudentModuleCollectionDao{
//
// @SerializedName("modules")
// @Expose
// private List<StudentModuleDao> data = null;
//
// public List<StudentModuleDao> getData() {
// return data;
// }
//
// public void setData(List<StudentModuleDao> data) {
// this.data = data;
// }
//
// @SerializedName("result")
// @Expose
// private String result;
// @SerializedName("message")
// @Expose
// private String message;
// @SerializedName("user")
// @Expose
// private User user;
//
// public String getResult() {
// return result;
// }
//
// public void setResult(String result) {
// this.result = result;
// }
//
// public String getMessage() {
// return message;
// }
//
// public void setMessage(String message) {
// this.message = message;
// }
//
// public User getUser() {
// return user;
// }
//
// public void setUser(User user) {
// this.user = user;
// }
//
// }
// Path: app/src/main/java/com/landtanin/studentattendancecheck/manager/http/ApiService.java
import com.landtanin.studentattendancecheck.dao.StudentModuleCollectionDao;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
import rx.Observable;
package com.landtanin.studentattendancecheck.manager.http;
/**
* Created by landtanin on 4/10/2017 AD.
*/
public interface ApiService {
@FormUrlEncoded
@POST("studentLogin/index.php") | Observable<StudentModuleCollectionDao> studentLoginCheck |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/main/java/io/scaledml/features/FirstPassRunner.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/BaseDisruptorRunner.java
// public abstract class BaseDisruptorRunner {
// private Disruptor<? extends TwoPhaseEvent<?>> disruptor;
// private Supplier<InputStream> inputStreamFactory;
// private boolean skipFirst;
// private Phaser phaser;
//
// public void process() throws IOException {
// try (FastBufferedInputStream stream = new FastBufferedInputStream(inputStreamFactory.get())) {
// Preconditions.checkArgument(phaser.getRegisteredParties() == 0);
// phaser.register();
// disruptor.start();
// RingBuffer<? extends TwoPhaseEvent> ringBuffer = disruptor.getRingBuffer();
// long cursor = ringBuffer.next();
// LineBytesBuffer buffer = ringBuffer.get(cursor).input();
// long lineNo = 0;
// ringBuffer.get(cursor).lineNo(lineNo);
// boolean needToSkipNext = skipFirst;
// while (buffer.readLineFrom(stream)) {
// if (needToSkipNext) {
// needToSkipNext = false;
// continue;
// }
// lineNo++;
// ringBuffer.publish(cursor);
// cursor = ringBuffer.next();
// buffer = ringBuffer.get(cursor).input();
// ringBuffer.get(cursor).lineNo(lineNo);
// }
// disruptor.shutdown();
// phaser.arriveAndAwaitAdvance();
// phaser.arriveAndDeregister();
// } finally {
// afterDisruptorProcessed();
// }
// }
//
// protected abstract void afterDisruptorProcessed() throws IOException;
//
// protected void setDisruptor(Disruptor<? extends TwoPhaseEvent<?>> disruptor) {
// this.disruptor = disruptor;
// }
//
// @Inject
// public void setInputStreamFactory(Supplier<InputStream> inputStreamFactory) {
// this.inputStreamFactory = inputStreamFactory;
// }
//
// @Inject
// public void setSkipFirst(@Named("skipFirst") boolean skipFirst) {
// this.skipFirst = skipFirst;
// }
//
// @Inject
// public void setPhaser(Phaser phaser) {
// this.phaser = phaser;
// }
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/TwoPhaseEvent.java
// public class TwoPhaseEvent<T> {
// public static <T> EventFactory<TwoPhaseEvent<T>> factory(EventFactory<T> outputFactory) {
// return () -> new TwoPhaseEvent<>(outputFactory.newInstance());
// }
//
// private final LineBytesBuffer input = new LineBytesBuffer();
// private long lineNo;
// private final T output;
//
// public TwoPhaseEvent(T output) {
// this.output = output;
// }
//
// public LineBytesBuffer input() {
// return input;
// }
//
// public T output() {
// return output;
// }
//
// public TwoPhaseEvent<T> lineNo(long lineNo) {
// this.lineNo = lineNo;
// return this;
// }
//
// public long lineNo() {
// return lineNo;
// }
// }
| import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.lmax.disruptor.dsl.Disruptor;
import io.scaledml.core.BaseDisruptorRunner;
import io.scaledml.core.TwoPhaseEvent;
import java.io.IOException; | package io.scaledml.features;
public class FirstPassRunner extends BaseDisruptorRunner {
@Override
protected void afterDisruptorProcessed() throws IOException {
}
@Inject | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/BaseDisruptorRunner.java
// public abstract class BaseDisruptorRunner {
// private Disruptor<? extends TwoPhaseEvent<?>> disruptor;
// private Supplier<InputStream> inputStreamFactory;
// private boolean skipFirst;
// private Phaser phaser;
//
// public void process() throws IOException {
// try (FastBufferedInputStream stream = new FastBufferedInputStream(inputStreamFactory.get())) {
// Preconditions.checkArgument(phaser.getRegisteredParties() == 0);
// phaser.register();
// disruptor.start();
// RingBuffer<? extends TwoPhaseEvent> ringBuffer = disruptor.getRingBuffer();
// long cursor = ringBuffer.next();
// LineBytesBuffer buffer = ringBuffer.get(cursor).input();
// long lineNo = 0;
// ringBuffer.get(cursor).lineNo(lineNo);
// boolean needToSkipNext = skipFirst;
// while (buffer.readLineFrom(stream)) {
// if (needToSkipNext) {
// needToSkipNext = false;
// continue;
// }
// lineNo++;
// ringBuffer.publish(cursor);
// cursor = ringBuffer.next();
// buffer = ringBuffer.get(cursor).input();
// ringBuffer.get(cursor).lineNo(lineNo);
// }
// disruptor.shutdown();
// phaser.arriveAndAwaitAdvance();
// phaser.arriveAndDeregister();
// } finally {
// afterDisruptorProcessed();
// }
// }
//
// protected abstract void afterDisruptorProcessed() throws IOException;
//
// protected void setDisruptor(Disruptor<? extends TwoPhaseEvent<?>> disruptor) {
// this.disruptor = disruptor;
// }
//
// @Inject
// public void setInputStreamFactory(Supplier<InputStream> inputStreamFactory) {
// this.inputStreamFactory = inputStreamFactory;
// }
//
// @Inject
// public void setSkipFirst(@Named("skipFirst") boolean skipFirst) {
// this.skipFirst = skipFirst;
// }
//
// @Inject
// public void setPhaser(Phaser phaser) {
// this.phaser = phaser;
// }
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/TwoPhaseEvent.java
// public class TwoPhaseEvent<T> {
// public static <T> EventFactory<TwoPhaseEvent<T>> factory(EventFactory<T> outputFactory) {
// return () -> new TwoPhaseEvent<>(outputFactory.newInstance());
// }
//
// private final LineBytesBuffer input = new LineBytesBuffer();
// private long lineNo;
// private final T output;
//
// public TwoPhaseEvent(T output) {
// this.output = output;
// }
//
// public LineBytesBuffer input() {
// return input;
// }
//
// public T output() {
// return output;
// }
//
// public TwoPhaseEvent<T> lineNo(long lineNo) {
// this.lineNo = lineNo;
// return this;
// }
//
// public long lineNo() {
// return lineNo;
// }
// }
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/features/FirstPassRunner.java
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.lmax.disruptor.dsl.Disruptor;
import io.scaledml.core.BaseDisruptorRunner;
import io.scaledml.core.TwoPhaseEvent;
import java.io.IOException;
package io.scaledml.features;
public class FirstPassRunner extends BaseDisruptorRunner {
@Override
protected void afterDisruptorProcessed() throws IOException {
}
@Inject | public FirstPassRunner disruptor(@Named("firstPassDisruptor") Disruptor<TwoPhaseEvent<Void>> disruptor) { |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/main/java/io/scaledml/features/NumericalFeaturesStatistics.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/util/Util.java
// public class Util {
// private final static HashFunction murmur = Hashing.murmur3_128(42);
//
// private final static HashFunction murmur32 = Hashing.murmur3_32(17);
// public static final double EPSILON = 0.0000001;
//
// public static boolean doublesEqual(double d1, double d2, double precision) {
// if (!Doubles.isFinite(d1) || !Doubles.isFinite(d2)) {
// return false;
// }
// return Math.abs(d1 - d2) < precision;
// }
//
// public static boolean doublesEqual(double d1, double d2) {
// return doublesEqual(d1, d2, EPSILON);
// }
//
// public static HashFunction murmur() {
// return murmur;
// }
//
// public static HashFunction murmur32() {
// return murmur32;
// }
//
// public static boolean doublesLess(double v1, double v2) {
// return v1 < v2 - EPSILON;
// }
// }
| import com.clearspring.analytics.stream.quantile.TDigest;
import com.clearspring.analytics.util.Preconditions;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.scaledml.core.util.Util;
import it.unimi.dsi.fastutil.doubles.Double2DoubleArrayMap;
import it.unimi.dsi.fastutil.doubles.Double2DoubleMap;
import it.unimi.dsi.fastutil.longs.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | digests.get(index).add(handler.digests().get(index));
}
}
for (long index : handler.counts().keySet()) {
long count = handler.counts().get(index);
counts.put(index, counts.get(index) + count);
}
for (long index : handler.minimums().keySet()) {
double min = handler.minimums().get(index);
minimums.put(index, Math.min(minimums.get(index), min));
}
for (long index : handler.maximums().keySet()) {
double max = handler.maximums().get(index);
maximums.put(index, Math.max(maximums.get(index), max));
}
}
private synchronized Long2ObjectMap<Binning> buildBinning() {
Long2ObjectMap<Binning> newBinnings = new Long2ObjectLinkedOpenHashMap<>();
for (long index : digests.keySet()) {
TDigest digest = digests.get(index);
double min = minimums.get(index);
Binning binning = buildBinning(digest, min);
newBinnings.put(index, binning);
}
return newBinnings;
}
Binning buildBinning(TDigest digest, double min) {
Binning binning = new Binning().addPercentile(min); | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/util/Util.java
// public class Util {
// private final static HashFunction murmur = Hashing.murmur3_128(42);
//
// private final static HashFunction murmur32 = Hashing.murmur3_32(17);
// public static final double EPSILON = 0.0000001;
//
// public static boolean doublesEqual(double d1, double d2, double precision) {
// if (!Doubles.isFinite(d1) || !Doubles.isFinite(d2)) {
// return false;
// }
// return Math.abs(d1 - d2) < precision;
// }
//
// public static boolean doublesEqual(double d1, double d2) {
// return doublesEqual(d1, d2, EPSILON);
// }
//
// public static HashFunction murmur() {
// return murmur;
// }
//
// public static HashFunction murmur32() {
// return murmur32;
// }
//
// public static boolean doublesLess(double v1, double v2) {
// return v1 < v2 - EPSILON;
// }
// }
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/features/NumericalFeaturesStatistics.java
import com.clearspring.analytics.stream.quantile.TDigest;
import com.clearspring.analytics.util.Preconditions;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.scaledml.core.util.Util;
import it.unimi.dsi.fastutil.doubles.Double2DoubleArrayMap;
import it.unimi.dsi.fastutil.doubles.Double2DoubleMap;
import it.unimi.dsi.fastutil.longs.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
digests.get(index).add(handler.digests().get(index));
}
}
for (long index : handler.counts().keySet()) {
long count = handler.counts().get(index);
counts.put(index, counts.get(index) + count);
}
for (long index : handler.minimums().keySet()) {
double min = handler.minimums().get(index);
minimums.put(index, Math.min(minimums.get(index), min));
}
for (long index : handler.maximums().keySet()) {
double max = handler.maximums().get(index);
maximums.put(index, Math.max(maximums.get(index), max));
}
}
private synchronized Long2ObjectMap<Binning> buildBinning() {
Long2ObjectMap<Binning> newBinnings = new Long2ObjectLinkedOpenHashMap<>();
for (long index : digests.keySet()) {
TDigest digest = digests.get(index);
double min = minimums.get(index);
Binning binning = buildBinning(digest, min);
newBinnings.put(index, binning);
}
return newBinnings;
}
Binning buildBinning(TDigest digest, double min) {
Binning binning = new Binning().addPercentile(min); | for (double p = percentsBinningStep; Util.doublesLess(p, 1.); p += percentsBinningStep) { |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/main/java/io/scaledml/core/outputformats/PrintStreamOutputFormat.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/SparseItem.java
// public class SparseItem {
// private final LongList categoricalIndexes = new LongArrayList();
// private final LongList numericalIndexes = new LongArrayList();
// private final DoubleList numericalValues = new DoubleArrayList();
// private String id;
// private double label;
//
// private final LongList indexesView = new MultiListsViewLongList(categoricalIndexes, numericalIndexes);
//
// public SparseItem addCategoricalIndex(long index) {
// categoricalIndexes.add(normalizeIndex(index));
// return this;
// }
//
// public SparseItem addNumericalIndex(long index, double value) {
// numericalIndexes.add(normalizeIndex(index));
// numericalValues.add(value);
// return this;
// }
//
// private long normalizeIndex(long ind) {
// return Math.abs(ind) % (1L << 40);
// }
//
// public LongList indexes() {
// return indexesView;
// }
//
// public double getValue(int i) {
// return i < categoricalIndexes.size() ? 1 : numericalValues.getDouble(i - categoricalIndexes.size());
// }
//
// public SparseItem label(double label) {
// this.label = Util.doublesEqual(1., label) ? 1. : 0.;
// return this;
// }
//
// public LongList categoricalIndexes() {
// return categoricalIndexes;
// }
//
// public LongList numericalIndexes() {
// return numericalIndexes;
// }
//
// public DoubleList numericalValues() {
// return numericalValues;
// }
//
// public SparseItem id(String id) {
// this.id = id;
// return this;
// }
//
// public double label() {
// return label;
// }
//
// public void clear() {
// label = 0.;
// id = null;
// numericalIndexes.clear();
// numericalValues.clear();
// categoricalIndexes.clear();
// }
//
// public String id() {
// return id;
// }
//
// public void write(LineBytesBuffer line) {
// line.putByte((byte) Math.signum(label));
// line.putString(id);
// line.putShort((short) categoricalIndexes.size());
// for (long index : categoricalIndexes) {
// line.putLong(index);
// }
// line.putShort((short) numericalIndexes.size());
// for (int i = 0; i < numericalIndexes.size(); i++) {
// line.putLong(numericalIndexes.getLong(i));
// line.putFloat((float) numericalValues.getDouble(i));
// }
// }
//
// public void read(LineBytesBuffer line) {
// clear();
// AtomicInteger cursor = new AtomicInteger(0);
// label = line.readByte(cursor) > 0 ? 1. : 0;
// id = line.readString(cursor);
// short factorsSize = line.readShort(cursor);
// for (short i = 0; i < factorsSize; i++) {
// categoricalIndexes.add(line.readLong(cursor));
// }
// short numericalSize = line.readShort(cursor);
// for (short i = 0; i < numericalSize; i++) {
// numericalIndexes.add(line.readLong(cursor));
// numericalValues.add(line.readFloat(cursor));
// }
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// SparseItem that = (SparseItem) o;
// return Objects.equals(id, that.id) &&
// Objects.equals(label, that.label) &&
// Objects.equals(categoricalIndexes, that.categoricalIndexes) &&
// Objects.equals(numericalIndexes, that.numericalIndexes) &&
// equalNumericalValues(that);
// }
//
// private boolean equalNumericalValues(SparseItem that) {
// if (numericalValues.size() != that.numericalValues.size()) {
// return false;
// }
// for (int i = 0; i < numericalValues.size(); i++) {
// if (!Util.doublesEqual(numericalValues.getDouble(i), that.numericalValues.getDouble(i), 0.00001)) {
// return false;
// }
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(id, label, categoricalIndexes, numericalIndexes);
// }
//
// @Override
// public String toString() {
// return MoreObjects.toStringHelper(getClass())
// .add("id", id)
// .add("label", label)
// .add("categorialIndexes", categoricalIndexes)
// .add("numericalIndexes", numericalIndexes)
// .add("numericalValues", numericalValues).toString();
// }
//
// public double scalarMultiply(DoubleArrayList weights) {
// double sum = 0.;
// for (int i = 0; i < categoricalIndexes.size(); i++) {
// sum += weights.getDouble(i);
// }
// for (int i = 0; i < numericalIndexes.size(); i++) {
// sum += numericalValues.getDouble(i) * weights.getDouble(i + categoricalIndexes.size());
// }
// return sum;
// }
//
// public SparseItem copyCategoricalFeaturesFrom(SparseItem item) {
// categoricalIndexes.addAll(item.categoricalIndexes);
// return this;
// }
// }
| import io.scaledml.core.SparseItem;
import java.io.IOException;
import java.io.PrintStream; | package io.scaledml.core.outputformats;
public class PrintStreamOutputFormat implements OutputFormat {
private PrintStream outputStream;
@Override | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/SparseItem.java
// public class SparseItem {
// private final LongList categoricalIndexes = new LongArrayList();
// private final LongList numericalIndexes = new LongArrayList();
// private final DoubleList numericalValues = new DoubleArrayList();
// private String id;
// private double label;
//
// private final LongList indexesView = new MultiListsViewLongList(categoricalIndexes, numericalIndexes);
//
// public SparseItem addCategoricalIndex(long index) {
// categoricalIndexes.add(normalizeIndex(index));
// return this;
// }
//
// public SparseItem addNumericalIndex(long index, double value) {
// numericalIndexes.add(normalizeIndex(index));
// numericalValues.add(value);
// return this;
// }
//
// private long normalizeIndex(long ind) {
// return Math.abs(ind) % (1L << 40);
// }
//
// public LongList indexes() {
// return indexesView;
// }
//
// public double getValue(int i) {
// return i < categoricalIndexes.size() ? 1 : numericalValues.getDouble(i - categoricalIndexes.size());
// }
//
// public SparseItem label(double label) {
// this.label = Util.doublesEqual(1., label) ? 1. : 0.;
// return this;
// }
//
// public LongList categoricalIndexes() {
// return categoricalIndexes;
// }
//
// public LongList numericalIndexes() {
// return numericalIndexes;
// }
//
// public DoubleList numericalValues() {
// return numericalValues;
// }
//
// public SparseItem id(String id) {
// this.id = id;
// return this;
// }
//
// public double label() {
// return label;
// }
//
// public void clear() {
// label = 0.;
// id = null;
// numericalIndexes.clear();
// numericalValues.clear();
// categoricalIndexes.clear();
// }
//
// public String id() {
// return id;
// }
//
// public void write(LineBytesBuffer line) {
// line.putByte((byte) Math.signum(label));
// line.putString(id);
// line.putShort((short) categoricalIndexes.size());
// for (long index : categoricalIndexes) {
// line.putLong(index);
// }
// line.putShort((short) numericalIndexes.size());
// for (int i = 0; i < numericalIndexes.size(); i++) {
// line.putLong(numericalIndexes.getLong(i));
// line.putFloat((float) numericalValues.getDouble(i));
// }
// }
//
// public void read(LineBytesBuffer line) {
// clear();
// AtomicInteger cursor = new AtomicInteger(0);
// label = line.readByte(cursor) > 0 ? 1. : 0;
// id = line.readString(cursor);
// short factorsSize = line.readShort(cursor);
// for (short i = 0; i < factorsSize; i++) {
// categoricalIndexes.add(line.readLong(cursor));
// }
// short numericalSize = line.readShort(cursor);
// for (short i = 0; i < numericalSize; i++) {
// numericalIndexes.add(line.readLong(cursor));
// numericalValues.add(line.readFloat(cursor));
// }
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// SparseItem that = (SparseItem) o;
// return Objects.equals(id, that.id) &&
// Objects.equals(label, that.label) &&
// Objects.equals(categoricalIndexes, that.categoricalIndexes) &&
// Objects.equals(numericalIndexes, that.numericalIndexes) &&
// equalNumericalValues(that);
// }
//
// private boolean equalNumericalValues(SparseItem that) {
// if (numericalValues.size() != that.numericalValues.size()) {
// return false;
// }
// for (int i = 0; i < numericalValues.size(); i++) {
// if (!Util.doublesEqual(numericalValues.getDouble(i), that.numericalValues.getDouble(i), 0.00001)) {
// return false;
// }
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(id, label, categoricalIndexes, numericalIndexes);
// }
//
// @Override
// public String toString() {
// return MoreObjects.toStringHelper(getClass())
// .add("id", id)
// .add("label", label)
// .add("categorialIndexes", categoricalIndexes)
// .add("numericalIndexes", numericalIndexes)
// .add("numericalValues", numericalValues).toString();
// }
//
// public double scalarMultiply(DoubleArrayList weights) {
// double sum = 0.;
// for (int i = 0; i < categoricalIndexes.size(); i++) {
// sum += weights.getDouble(i);
// }
// for (int i = 0; i < numericalIndexes.size(); i++) {
// sum += numericalValues.getDouble(i) * weights.getDouble(i + categoricalIndexes.size());
// }
// return sum;
// }
//
// public SparseItem copyCategoricalFeaturesFrom(SparseItem item) {
// categoricalIndexes.addAll(item.categoricalIndexes);
// return this;
// }
// }
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/outputformats/PrintStreamOutputFormat.java
import io.scaledml.core.SparseItem;
import java.io.IOException;
import java.io.PrintStream;
package io.scaledml.core.outputformats;
public class PrintStreamOutputFormat implements OutputFormat {
private PrintStream outputStream;
@Override | public void emit(SparseItem item, double prediction) { |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/main/java/io/scaledml/core/outputformats/NullOutputFormat.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/SparseItem.java
// public class SparseItem {
// private final LongList categoricalIndexes = new LongArrayList();
// private final LongList numericalIndexes = new LongArrayList();
// private final DoubleList numericalValues = new DoubleArrayList();
// private String id;
// private double label;
//
// private final LongList indexesView = new MultiListsViewLongList(categoricalIndexes, numericalIndexes);
//
// public SparseItem addCategoricalIndex(long index) {
// categoricalIndexes.add(normalizeIndex(index));
// return this;
// }
//
// public SparseItem addNumericalIndex(long index, double value) {
// numericalIndexes.add(normalizeIndex(index));
// numericalValues.add(value);
// return this;
// }
//
// private long normalizeIndex(long ind) {
// return Math.abs(ind) % (1L << 40);
// }
//
// public LongList indexes() {
// return indexesView;
// }
//
// public double getValue(int i) {
// return i < categoricalIndexes.size() ? 1 : numericalValues.getDouble(i - categoricalIndexes.size());
// }
//
// public SparseItem label(double label) {
// this.label = Util.doublesEqual(1., label) ? 1. : 0.;
// return this;
// }
//
// public LongList categoricalIndexes() {
// return categoricalIndexes;
// }
//
// public LongList numericalIndexes() {
// return numericalIndexes;
// }
//
// public DoubleList numericalValues() {
// return numericalValues;
// }
//
// public SparseItem id(String id) {
// this.id = id;
// return this;
// }
//
// public double label() {
// return label;
// }
//
// public void clear() {
// label = 0.;
// id = null;
// numericalIndexes.clear();
// numericalValues.clear();
// categoricalIndexes.clear();
// }
//
// public String id() {
// return id;
// }
//
// public void write(LineBytesBuffer line) {
// line.putByte((byte) Math.signum(label));
// line.putString(id);
// line.putShort((short) categoricalIndexes.size());
// for (long index : categoricalIndexes) {
// line.putLong(index);
// }
// line.putShort((short) numericalIndexes.size());
// for (int i = 0; i < numericalIndexes.size(); i++) {
// line.putLong(numericalIndexes.getLong(i));
// line.putFloat((float) numericalValues.getDouble(i));
// }
// }
//
// public void read(LineBytesBuffer line) {
// clear();
// AtomicInteger cursor = new AtomicInteger(0);
// label = line.readByte(cursor) > 0 ? 1. : 0;
// id = line.readString(cursor);
// short factorsSize = line.readShort(cursor);
// for (short i = 0; i < factorsSize; i++) {
// categoricalIndexes.add(line.readLong(cursor));
// }
// short numericalSize = line.readShort(cursor);
// for (short i = 0; i < numericalSize; i++) {
// numericalIndexes.add(line.readLong(cursor));
// numericalValues.add(line.readFloat(cursor));
// }
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// SparseItem that = (SparseItem) o;
// return Objects.equals(id, that.id) &&
// Objects.equals(label, that.label) &&
// Objects.equals(categoricalIndexes, that.categoricalIndexes) &&
// Objects.equals(numericalIndexes, that.numericalIndexes) &&
// equalNumericalValues(that);
// }
//
// private boolean equalNumericalValues(SparseItem that) {
// if (numericalValues.size() != that.numericalValues.size()) {
// return false;
// }
// for (int i = 0; i < numericalValues.size(); i++) {
// if (!Util.doublesEqual(numericalValues.getDouble(i), that.numericalValues.getDouble(i), 0.00001)) {
// return false;
// }
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(id, label, categoricalIndexes, numericalIndexes);
// }
//
// @Override
// public String toString() {
// return MoreObjects.toStringHelper(getClass())
// .add("id", id)
// .add("label", label)
// .add("categorialIndexes", categoricalIndexes)
// .add("numericalIndexes", numericalIndexes)
// .add("numericalValues", numericalValues).toString();
// }
//
// public double scalarMultiply(DoubleArrayList weights) {
// double sum = 0.;
// for (int i = 0; i < categoricalIndexes.size(); i++) {
// sum += weights.getDouble(i);
// }
// for (int i = 0; i < numericalIndexes.size(); i++) {
// sum += numericalValues.getDouble(i) * weights.getDouble(i + categoricalIndexes.size());
// }
// return sum;
// }
//
// public SparseItem copyCategoricalFeaturesFrom(SparseItem item) {
// categoricalIndexes.addAll(item.categoricalIndexes);
// return this;
// }
// }
| import io.scaledml.core.SparseItem;
import java.io.IOException; | package io.scaledml.core.outputformats;
public class NullOutputFormat implements OutputFormat {
@Override | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/SparseItem.java
// public class SparseItem {
// private final LongList categoricalIndexes = new LongArrayList();
// private final LongList numericalIndexes = new LongArrayList();
// private final DoubleList numericalValues = new DoubleArrayList();
// private String id;
// private double label;
//
// private final LongList indexesView = new MultiListsViewLongList(categoricalIndexes, numericalIndexes);
//
// public SparseItem addCategoricalIndex(long index) {
// categoricalIndexes.add(normalizeIndex(index));
// return this;
// }
//
// public SparseItem addNumericalIndex(long index, double value) {
// numericalIndexes.add(normalizeIndex(index));
// numericalValues.add(value);
// return this;
// }
//
// private long normalizeIndex(long ind) {
// return Math.abs(ind) % (1L << 40);
// }
//
// public LongList indexes() {
// return indexesView;
// }
//
// public double getValue(int i) {
// return i < categoricalIndexes.size() ? 1 : numericalValues.getDouble(i - categoricalIndexes.size());
// }
//
// public SparseItem label(double label) {
// this.label = Util.doublesEqual(1., label) ? 1. : 0.;
// return this;
// }
//
// public LongList categoricalIndexes() {
// return categoricalIndexes;
// }
//
// public LongList numericalIndexes() {
// return numericalIndexes;
// }
//
// public DoubleList numericalValues() {
// return numericalValues;
// }
//
// public SparseItem id(String id) {
// this.id = id;
// return this;
// }
//
// public double label() {
// return label;
// }
//
// public void clear() {
// label = 0.;
// id = null;
// numericalIndexes.clear();
// numericalValues.clear();
// categoricalIndexes.clear();
// }
//
// public String id() {
// return id;
// }
//
// public void write(LineBytesBuffer line) {
// line.putByte((byte) Math.signum(label));
// line.putString(id);
// line.putShort((short) categoricalIndexes.size());
// for (long index : categoricalIndexes) {
// line.putLong(index);
// }
// line.putShort((short) numericalIndexes.size());
// for (int i = 0; i < numericalIndexes.size(); i++) {
// line.putLong(numericalIndexes.getLong(i));
// line.putFloat((float) numericalValues.getDouble(i));
// }
// }
//
// public void read(LineBytesBuffer line) {
// clear();
// AtomicInteger cursor = new AtomicInteger(0);
// label = line.readByte(cursor) > 0 ? 1. : 0;
// id = line.readString(cursor);
// short factorsSize = line.readShort(cursor);
// for (short i = 0; i < factorsSize; i++) {
// categoricalIndexes.add(line.readLong(cursor));
// }
// short numericalSize = line.readShort(cursor);
// for (short i = 0; i < numericalSize; i++) {
// numericalIndexes.add(line.readLong(cursor));
// numericalValues.add(line.readFloat(cursor));
// }
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// SparseItem that = (SparseItem) o;
// return Objects.equals(id, that.id) &&
// Objects.equals(label, that.label) &&
// Objects.equals(categoricalIndexes, that.categoricalIndexes) &&
// Objects.equals(numericalIndexes, that.numericalIndexes) &&
// equalNumericalValues(that);
// }
//
// private boolean equalNumericalValues(SparseItem that) {
// if (numericalValues.size() != that.numericalValues.size()) {
// return false;
// }
// for (int i = 0; i < numericalValues.size(); i++) {
// if (!Util.doublesEqual(numericalValues.getDouble(i), that.numericalValues.getDouble(i), 0.00001)) {
// return false;
// }
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(id, label, categoricalIndexes, numericalIndexes);
// }
//
// @Override
// public String toString() {
// return MoreObjects.toStringHelper(getClass())
// .add("id", id)
// .add("label", label)
// .add("categorialIndexes", categoricalIndexes)
// .add("numericalIndexes", numericalIndexes)
// .add("numericalValues", numericalValues).toString();
// }
//
// public double scalarMultiply(DoubleArrayList weights) {
// double sum = 0.;
// for (int i = 0; i < categoricalIndexes.size(); i++) {
// sum += weights.getDouble(i);
// }
// for (int i = 0; i < numericalIndexes.size(); i++) {
// sum += numericalValues.getDouble(i) * weights.getDouble(i + categoricalIndexes.size());
// }
// return sum;
// }
//
// public SparseItem copyCategoricalFeaturesFrom(SparseItem item) {
// categoricalIndexes.addAll(item.categoricalIndexes);
// return this;
// }
// }
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/outputformats/NullOutputFormat.java
import io.scaledml.core.SparseItem;
import java.io.IOException;
package io.scaledml.core.outputformats;
public class NullOutputFormat implements OutputFormat {
@Override | public void emit(SparseItem item, double prediction) { |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/main/java/io/scaledml/ftrl/FTRLProximalAlgorithm.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/SparseItem.java
// public class SparseItem {
// private final LongList categoricalIndexes = new LongArrayList();
// private final LongList numericalIndexes = new LongArrayList();
// private final DoubleList numericalValues = new DoubleArrayList();
// private String id;
// private double label;
//
// private final LongList indexesView = new MultiListsViewLongList(categoricalIndexes, numericalIndexes);
//
// public SparseItem addCategoricalIndex(long index) {
// categoricalIndexes.add(normalizeIndex(index));
// return this;
// }
//
// public SparseItem addNumericalIndex(long index, double value) {
// numericalIndexes.add(normalizeIndex(index));
// numericalValues.add(value);
// return this;
// }
//
// private long normalizeIndex(long ind) {
// return Math.abs(ind) % (1L << 40);
// }
//
// public LongList indexes() {
// return indexesView;
// }
//
// public double getValue(int i) {
// return i < categoricalIndexes.size() ? 1 : numericalValues.getDouble(i - categoricalIndexes.size());
// }
//
// public SparseItem label(double label) {
// this.label = Util.doublesEqual(1., label) ? 1. : 0.;
// return this;
// }
//
// public LongList categoricalIndexes() {
// return categoricalIndexes;
// }
//
// public LongList numericalIndexes() {
// return numericalIndexes;
// }
//
// public DoubleList numericalValues() {
// return numericalValues;
// }
//
// public SparseItem id(String id) {
// this.id = id;
// return this;
// }
//
// public double label() {
// return label;
// }
//
// public void clear() {
// label = 0.;
// id = null;
// numericalIndexes.clear();
// numericalValues.clear();
// categoricalIndexes.clear();
// }
//
// public String id() {
// return id;
// }
//
// public void write(LineBytesBuffer line) {
// line.putByte((byte) Math.signum(label));
// line.putString(id);
// line.putShort((short) categoricalIndexes.size());
// for (long index : categoricalIndexes) {
// line.putLong(index);
// }
// line.putShort((short) numericalIndexes.size());
// for (int i = 0; i < numericalIndexes.size(); i++) {
// line.putLong(numericalIndexes.getLong(i));
// line.putFloat((float) numericalValues.getDouble(i));
// }
// }
//
// public void read(LineBytesBuffer line) {
// clear();
// AtomicInteger cursor = new AtomicInteger(0);
// label = line.readByte(cursor) > 0 ? 1. : 0;
// id = line.readString(cursor);
// short factorsSize = line.readShort(cursor);
// for (short i = 0; i < factorsSize; i++) {
// categoricalIndexes.add(line.readLong(cursor));
// }
// short numericalSize = line.readShort(cursor);
// for (short i = 0; i < numericalSize; i++) {
// numericalIndexes.add(line.readLong(cursor));
// numericalValues.add(line.readFloat(cursor));
// }
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// SparseItem that = (SparseItem) o;
// return Objects.equals(id, that.id) &&
// Objects.equals(label, that.label) &&
// Objects.equals(categoricalIndexes, that.categoricalIndexes) &&
// Objects.equals(numericalIndexes, that.numericalIndexes) &&
// equalNumericalValues(that);
// }
//
// private boolean equalNumericalValues(SparseItem that) {
// if (numericalValues.size() != that.numericalValues.size()) {
// return false;
// }
// for (int i = 0; i < numericalValues.size(); i++) {
// if (!Util.doublesEqual(numericalValues.getDouble(i), that.numericalValues.getDouble(i), 0.00001)) {
// return false;
// }
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(id, label, categoricalIndexes, numericalIndexes);
// }
//
// @Override
// public String toString() {
// return MoreObjects.toStringHelper(getClass())
// .add("id", id)
// .add("label", label)
// .add("categorialIndexes", categoricalIndexes)
// .add("numericalIndexes", numericalIndexes)
// .add("numericalValues", numericalValues).toString();
// }
//
// public double scalarMultiply(DoubleArrayList weights) {
// double sum = 0.;
// for (int i = 0; i < categoricalIndexes.size(); i++) {
// sum += weights.getDouble(i);
// }
// for (int i = 0; i < numericalIndexes.size(); i++) {
// sum += numericalValues.getDouble(i) * weights.getDouble(i + categoricalIndexes.size());
// }
// return sum;
// }
//
// public SparseItem copyCategoricalFeaturesFrom(SparseItem item) {
// categoricalIndexes.addAll(item.categoricalIndexes);
// return this;
// }
// }
| import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.scaledml.core.SparseItem;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; | package io.scaledml.ftrl;
public class FTRLProximalAlgorithm {
private FtrlProximalModel model;
private boolean testOnly;
private final DoubleArrayList currentN = new DoubleArrayList();
private final DoubleArrayList currentZ = new DoubleArrayList();
private final DoubleArrayList currentWeights = new DoubleArrayList();
| // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/SparseItem.java
// public class SparseItem {
// private final LongList categoricalIndexes = new LongArrayList();
// private final LongList numericalIndexes = new LongArrayList();
// private final DoubleList numericalValues = new DoubleArrayList();
// private String id;
// private double label;
//
// private final LongList indexesView = new MultiListsViewLongList(categoricalIndexes, numericalIndexes);
//
// public SparseItem addCategoricalIndex(long index) {
// categoricalIndexes.add(normalizeIndex(index));
// return this;
// }
//
// public SparseItem addNumericalIndex(long index, double value) {
// numericalIndexes.add(normalizeIndex(index));
// numericalValues.add(value);
// return this;
// }
//
// private long normalizeIndex(long ind) {
// return Math.abs(ind) % (1L << 40);
// }
//
// public LongList indexes() {
// return indexesView;
// }
//
// public double getValue(int i) {
// return i < categoricalIndexes.size() ? 1 : numericalValues.getDouble(i - categoricalIndexes.size());
// }
//
// public SparseItem label(double label) {
// this.label = Util.doublesEqual(1., label) ? 1. : 0.;
// return this;
// }
//
// public LongList categoricalIndexes() {
// return categoricalIndexes;
// }
//
// public LongList numericalIndexes() {
// return numericalIndexes;
// }
//
// public DoubleList numericalValues() {
// return numericalValues;
// }
//
// public SparseItem id(String id) {
// this.id = id;
// return this;
// }
//
// public double label() {
// return label;
// }
//
// public void clear() {
// label = 0.;
// id = null;
// numericalIndexes.clear();
// numericalValues.clear();
// categoricalIndexes.clear();
// }
//
// public String id() {
// return id;
// }
//
// public void write(LineBytesBuffer line) {
// line.putByte((byte) Math.signum(label));
// line.putString(id);
// line.putShort((short) categoricalIndexes.size());
// for (long index : categoricalIndexes) {
// line.putLong(index);
// }
// line.putShort((short) numericalIndexes.size());
// for (int i = 0; i < numericalIndexes.size(); i++) {
// line.putLong(numericalIndexes.getLong(i));
// line.putFloat((float) numericalValues.getDouble(i));
// }
// }
//
// public void read(LineBytesBuffer line) {
// clear();
// AtomicInteger cursor = new AtomicInteger(0);
// label = line.readByte(cursor) > 0 ? 1. : 0;
// id = line.readString(cursor);
// short factorsSize = line.readShort(cursor);
// for (short i = 0; i < factorsSize; i++) {
// categoricalIndexes.add(line.readLong(cursor));
// }
// short numericalSize = line.readShort(cursor);
// for (short i = 0; i < numericalSize; i++) {
// numericalIndexes.add(line.readLong(cursor));
// numericalValues.add(line.readFloat(cursor));
// }
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// SparseItem that = (SparseItem) o;
// return Objects.equals(id, that.id) &&
// Objects.equals(label, that.label) &&
// Objects.equals(categoricalIndexes, that.categoricalIndexes) &&
// Objects.equals(numericalIndexes, that.numericalIndexes) &&
// equalNumericalValues(that);
// }
//
// private boolean equalNumericalValues(SparseItem that) {
// if (numericalValues.size() != that.numericalValues.size()) {
// return false;
// }
// for (int i = 0; i < numericalValues.size(); i++) {
// if (!Util.doublesEqual(numericalValues.getDouble(i), that.numericalValues.getDouble(i), 0.00001)) {
// return false;
// }
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(id, label, categoricalIndexes, numericalIndexes);
// }
//
// @Override
// public String toString() {
// return MoreObjects.toStringHelper(getClass())
// .add("id", id)
// .add("label", label)
// .add("categorialIndexes", categoricalIndexes)
// .add("numericalIndexes", numericalIndexes)
// .add("numericalValues", numericalValues).toString();
// }
//
// public double scalarMultiply(DoubleArrayList weights) {
// double sum = 0.;
// for (int i = 0; i < categoricalIndexes.size(); i++) {
// sum += weights.getDouble(i);
// }
// for (int i = 0; i < numericalIndexes.size(); i++) {
// sum += numericalValues.getDouble(i) * weights.getDouble(i + categoricalIndexes.size());
// }
// return sum;
// }
//
// public SparseItem copyCategoricalFeaturesFrom(SparseItem item) {
// categoricalIndexes.addAll(item.categoricalIndexes);
// return this;
// }
// }
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/ftrl/FTRLProximalAlgorithm.java
import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.scaledml.core.SparseItem;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
package io.scaledml.ftrl;
public class FTRLProximalAlgorithm {
private FtrlProximalModel model;
private boolean testOnly;
private final DoubleArrayList currentN = new DoubleArrayList();
private final DoubleArrayList currentZ = new DoubleArrayList();
private final DoubleArrayList currentWeights = new DoubleArrayList();
| public double learn(SparseItem item, Increment increment) { |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/test/java/io/scaledml/core/inputformats/ColumnsMaskTest.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/inputformats/ColumnsMask.java
// public static enum ColumnType {
// LABEL,
// ID,
// NUMERICAL,
// CATEGORICAL
// }
| import io.scaledml.core.inputformats.ColumnsMask.ColumnType;
import org.junit.Test;
import static org.junit.Assert.*; | package io.scaledml.core.inputformats;
public class ColumnsMaskTest {
@Test
public void testParse1() {
ColumnsMask mask = new ColumnsMask("lc[37]n"); | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/inputformats/ColumnsMask.java
// public static enum ColumnType {
// LABEL,
// ID,
// NUMERICAL,
// CATEGORICAL
// }
// Path: fast-ftrl-proximal/src/test/java/io/scaledml/core/inputformats/ColumnsMaskTest.java
import io.scaledml.core.inputformats.ColumnsMask.ColumnType;
import org.junit.Test;
import static org.junit.Assert.*;
package io.scaledml.core.inputformats;
public class ColumnsMaskTest {
@Test
public void testParse1() {
ColumnsMask mask = new ColumnsMask("lc[37]n"); | assertEquals(ColumnType.LABEL, mask.getCategory(0)); |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/main/java/io/scaledml/features/Binning.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/util/Util.java
// public class Util {
// private final static HashFunction murmur = Hashing.murmur3_128(42);
//
// private final static HashFunction murmur32 = Hashing.murmur3_32(17);
// public static final double EPSILON = 0.0000001;
//
// public static boolean doublesEqual(double d1, double d2, double precision) {
// if (!Doubles.isFinite(d1) || !Doubles.isFinite(d2)) {
// return false;
// }
// return Math.abs(d1 - d2) < precision;
// }
//
// public static boolean doublesEqual(double d1, double d2) {
// return doublesEqual(d1, d2, EPSILON);
// }
//
// public static HashFunction murmur() {
// return murmur;
// }
//
// public static HashFunction murmur32() {
// return murmur32;
// }
//
// public static boolean doublesLess(double v1, double v2) {
// return v1 < v2 - EPSILON;
// }
// }
| import io.scaledml.core.util.Util;
import it.unimi.dsi.fastutil.doubles.*;
import java.util.Collections; | package io.scaledml.features;
public class Binning {
private final DoubleList percentiles = new DoubleArrayList();
public Binning addPercentile(double percentile) {
percentiles.add(percentile);
return this;
}
public Binning finishBuild() {
percentiles.sort(Double::compare);
for (int i = 0; i < percentiles.size() - 1; i++) { | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/util/Util.java
// public class Util {
// private final static HashFunction murmur = Hashing.murmur3_128(42);
//
// private final static HashFunction murmur32 = Hashing.murmur3_32(17);
// public static final double EPSILON = 0.0000001;
//
// public static boolean doublesEqual(double d1, double d2, double precision) {
// if (!Doubles.isFinite(d1) || !Doubles.isFinite(d2)) {
// return false;
// }
// return Math.abs(d1 - d2) < precision;
// }
//
// public static boolean doublesEqual(double d1, double d2) {
// return doublesEqual(d1, d2, EPSILON);
// }
//
// public static HashFunction murmur() {
// return murmur;
// }
//
// public static HashFunction murmur32() {
// return murmur32;
// }
//
// public static boolean doublesLess(double v1, double v2) {
// return v1 < v2 - EPSILON;
// }
// }
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/features/Binning.java
import io.scaledml.core.util.Util;
import it.unimi.dsi.fastutil.doubles.*;
import java.util.Collections;
package io.scaledml.features;
public class Binning {
private final DoubleList percentiles = new DoubleArrayList();
public Binning addPercentile(double percentile) {
percentiles.add(percentile);
return this;
}
public Binning finishBuild() {
percentiles.sort(Double::compare);
for (int i = 0; i < percentiles.size() - 1; i++) { | if (Util.doublesEqual(percentiles.getDouble(i), percentiles.getDouble(i + 1), 0.0001)) { |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/test/java/io/scaledml/features/NumericalFeaturesStatisticsTest.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/util/Util.java
// public class Util {
// private final static HashFunction murmur = Hashing.murmur3_128(42);
//
// private final static HashFunction murmur32 = Hashing.murmur3_32(17);
// public static final double EPSILON = 0.0000001;
//
// public static boolean doublesEqual(double d1, double d2, double precision) {
// if (!Doubles.isFinite(d1) || !Doubles.isFinite(d2)) {
// return false;
// }
// return Math.abs(d1 - d2) < precision;
// }
//
// public static boolean doublesEqual(double d1, double d2) {
// return doublesEqual(d1, d2, EPSILON);
// }
//
// public static HashFunction murmur() {
// return murmur;
// }
//
// public static HashFunction murmur32() {
// return murmur32;
// }
//
// public static boolean doublesLess(double v1, double v2) {
// return v1 < v2 - EPSILON;
// }
// }
| import com.clearspring.analytics.stream.quantile.TDigest;
import com.clearspring.analytics.util.Preconditions;
import io.scaledml.core.util.Util;
import it.unimi.dsi.fastutil.doubles.Double2DoubleMap;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import org.junit.Test;
import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.*; | digest.add(ThreadLocalRandom.current().nextDouble());
}
NumericalFeaturesStatistics st = new NumericalFeaturesStatistics()
.percentsHistogramStep(0.01);
Binning binning = st.buildBinning(digest, 0.);
assertEquals(0, binning.getInsertionPoint(0.));
assertEquals(-1, binning.getInsertionPoint(-0.1));
assertEquals(99, binning.getInsertionPoint(1.));
assertEquals(99, binning.getInsertionPoint(Double.MAX_VALUE));
int middleInsertion = binning.getInsertionPoint(0.5);
assertTrue("middleInsertion is " + middleInsertion, middleInsertion > 45 && middleInsertion < 55);
int quarterInsertion = binning.getInsertionPoint(0.25);
assertTrue("quarterInsertion is " + quarterInsertion, quarterInsertion > 20 && quarterInsertion < 30);
int thirdQuarterInsertion = binning.getInsertionPoint(0.75);
assertTrue("thirdQuarterInsertion is " + thirdQuarterInsertion, thirdQuarterInsertion > 70 && thirdQuarterInsertion < 80);
}
@Test
public void testBuildHistogram() {
Binning binning = new Binning();
for (int i = 0; i < 99; i++) {
binning.addPercentile(ThreadLocalRandom.current().nextDouble());
}
binning.addPercentile(0.).finishBuild();
NumericalFeaturesStatistics st = new NumericalFeaturesStatistics()
.percentsHistogramStep(0.01);
Double2DoubleMap histogram = st.buildHistogram(binning, 0, 1);
assertEquals(102, histogram.size());
double sum = histogram.values()
.stream().mapToDouble(Double::doubleValue).sum(); | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/util/Util.java
// public class Util {
// private final static HashFunction murmur = Hashing.murmur3_128(42);
//
// private final static HashFunction murmur32 = Hashing.murmur3_32(17);
// public static final double EPSILON = 0.0000001;
//
// public static boolean doublesEqual(double d1, double d2, double precision) {
// if (!Doubles.isFinite(d1) || !Doubles.isFinite(d2)) {
// return false;
// }
// return Math.abs(d1 - d2) < precision;
// }
//
// public static boolean doublesEqual(double d1, double d2) {
// return doublesEqual(d1, d2, EPSILON);
// }
//
// public static HashFunction murmur() {
// return murmur;
// }
//
// public static HashFunction murmur32() {
// return murmur32;
// }
//
// public static boolean doublesLess(double v1, double v2) {
// return v1 < v2 - EPSILON;
// }
// }
// Path: fast-ftrl-proximal/src/test/java/io/scaledml/features/NumericalFeaturesStatisticsTest.java
import com.clearspring.analytics.stream.quantile.TDigest;
import com.clearspring.analytics.util.Preconditions;
import io.scaledml.core.util.Util;
import it.unimi.dsi.fastutil.doubles.Double2DoubleMap;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import org.junit.Test;
import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.*;
digest.add(ThreadLocalRandom.current().nextDouble());
}
NumericalFeaturesStatistics st = new NumericalFeaturesStatistics()
.percentsHistogramStep(0.01);
Binning binning = st.buildBinning(digest, 0.);
assertEquals(0, binning.getInsertionPoint(0.));
assertEquals(-1, binning.getInsertionPoint(-0.1));
assertEquals(99, binning.getInsertionPoint(1.));
assertEquals(99, binning.getInsertionPoint(Double.MAX_VALUE));
int middleInsertion = binning.getInsertionPoint(0.5);
assertTrue("middleInsertion is " + middleInsertion, middleInsertion > 45 && middleInsertion < 55);
int quarterInsertion = binning.getInsertionPoint(0.25);
assertTrue("quarterInsertion is " + quarterInsertion, quarterInsertion > 20 && quarterInsertion < 30);
int thirdQuarterInsertion = binning.getInsertionPoint(0.75);
assertTrue("thirdQuarterInsertion is " + thirdQuarterInsertion, thirdQuarterInsertion > 70 && thirdQuarterInsertion < 80);
}
@Test
public void testBuildHistogram() {
Binning binning = new Binning();
for (int i = 0; i < 99; i++) {
binning.addPercentile(ThreadLocalRandom.current().nextDouble());
}
binning.addPercentile(0.).finishBuild();
NumericalFeaturesStatistics st = new NumericalFeaturesStatistics()
.percentsHistogramStep(0.01);
Double2DoubleMap histogram = st.buildHistogram(binning, 0, 1);
assertEquals(102, histogram.size());
double sum = histogram.values()
.stream().mapToDouble(Double::doubleValue).sum(); | assertEquals(1., sum, Util.EPSILON); |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/main/java/io/scaledml/ftrl/FtrlProximalRunner.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/BaseDisruptorRunner.java
// public abstract class BaseDisruptorRunner {
// private Disruptor<? extends TwoPhaseEvent<?>> disruptor;
// private Supplier<InputStream> inputStreamFactory;
// private boolean skipFirst;
// private Phaser phaser;
//
// public void process() throws IOException {
// try (FastBufferedInputStream stream = new FastBufferedInputStream(inputStreamFactory.get())) {
// Preconditions.checkArgument(phaser.getRegisteredParties() == 0);
// phaser.register();
// disruptor.start();
// RingBuffer<? extends TwoPhaseEvent> ringBuffer = disruptor.getRingBuffer();
// long cursor = ringBuffer.next();
// LineBytesBuffer buffer = ringBuffer.get(cursor).input();
// long lineNo = 0;
// ringBuffer.get(cursor).lineNo(lineNo);
// boolean needToSkipNext = skipFirst;
// while (buffer.readLineFrom(stream)) {
// if (needToSkipNext) {
// needToSkipNext = false;
// continue;
// }
// lineNo++;
// ringBuffer.publish(cursor);
// cursor = ringBuffer.next();
// buffer = ringBuffer.get(cursor).input();
// ringBuffer.get(cursor).lineNo(lineNo);
// }
// disruptor.shutdown();
// phaser.arriveAndAwaitAdvance();
// phaser.arriveAndDeregister();
// } finally {
// afterDisruptorProcessed();
// }
// }
//
// protected abstract void afterDisruptorProcessed() throws IOException;
//
// protected void setDisruptor(Disruptor<? extends TwoPhaseEvent<?>> disruptor) {
// this.disruptor = disruptor;
// }
//
// @Inject
// public void setInputStreamFactory(Supplier<InputStream> inputStreamFactory) {
// this.inputStreamFactory = inputStreamFactory;
// }
//
// @Inject
// public void setSkipFirst(@Named("skipFirst") boolean skipFirst) {
// this.skipFirst = skipFirst;
// }
//
// @Inject
// public void setPhaser(Phaser phaser) {
// this.phaser = phaser;
// }
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/outputformats/OutputFormat.java
// public interface OutputFormat extends Closeable {
// void emit(SparseItem item, double prediction);
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/TwoPhaseEvent.java
// public class TwoPhaseEvent<T> {
// public static <T> EventFactory<TwoPhaseEvent<T>> factory(EventFactory<T> outputFactory) {
// return () -> new TwoPhaseEvent<>(outputFactory.newInstance());
// }
//
// private final LineBytesBuffer input = new LineBytesBuffer();
// private long lineNo;
// private final T output;
//
// public TwoPhaseEvent(T output) {
// this.output = output;
// }
//
// public LineBytesBuffer input() {
// return input;
// }
//
// public T output() {
// return output;
// }
//
// public TwoPhaseEvent<T> lineNo(long lineNo) {
// this.lineNo = lineNo;
// return this;
// }
//
// public long lineNo() {
// return lineNo;
// }
// }
| import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.lmax.disruptor.dsl.Disruptor;
import io.scaledml.core.BaseDisruptorRunner;
import io.scaledml.core.outputformats.OutputFormat;
import io.scaledml.core.TwoPhaseEvent;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional; | package io.scaledml.ftrl;
public class FtrlProximalRunner extends BaseDisruptorRunner {
private FtrlProximalModel model;
private Path outputForModelPath; | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/BaseDisruptorRunner.java
// public abstract class BaseDisruptorRunner {
// private Disruptor<? extends TwoPhaseEvent<?>> disruptor;
// private Supplier<InputStream> inputStreamFactory;
// private boolean skipFirst;
// private Phaser phaser;
//
// public void process() throws IOException {
// try (FastBufferedInputStream stream = new FastBufferedInputStream(inputStreamFactory.get())) {
// Preconditions.checkArgument(phaser.getRegisteredParties() == 0);
// phaser.register();
// disruptor.start();
// RingBuffer<? extends TwoPhaseEvent> ringBuffer = disruptor.getRingBuffer();
// long cursor = ringBuffer.next();
// LineBytesBuffer buffer = ringBuffer.get(cursor).input();
// long lineNo = 0;
// ringBuffer.get(cursor).lineNo(lineNo);
// boolean needToSkipNext = skipFirst;
// while (buffer.readLineFrom(stream)) {
// if (needToSkipNext) {
// needToSkipNext = false;
// continue;
// }
// lineNo++;
// ringBuffer.publish(cursor);
// cursor = ringBuffer.next();
// buffer = ringBuffer.get(cursor).input();
// ringBuffer.get(cursor).lineNo(lineNo);
// }
// disruptor.shutdown();
// phaser.arriveAndAwaitAdvance();
// phaser.arriveAndDeregister();
// } finally {
// afterDisruptorProcessed();
// }
// }
//
// protected abstract void afterDisruptorProcessed() throws IOException;
//
// protected void setDisruptor(Disruptor<? extends TwoPhaseEvent<?>> disruptor) {
// this.disruptor = disruptor;
// }
//
// @Inject
// public void setInputStreamFactory(Supplier<InputStream> inputStreamFactory) {
// this.inputStreamFactory = inputStreamFactory;
// }
//
// @Inject
// public void setSkipFirst(@Named("skipFirst") boolean skipFirst) {
// this.skipFirst = skipFirst;
// }
//
// @Inject
// public void setPhaser(Phaser phaser) {
// this.phaser = phaser;
// }
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/outputformats/OutputFormat.java
// public interface OutputFormat extends Closeable {
// void emit(SparseItem item, double prediction);
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/TwoPhaseEvent.java
// public class TwoPhaseEvent<T> {
// public static <T> EventFactory<TwoPhaseEvent<T>> factory(EventFactory<T> outputFactory) {
// return () -> new TwoPhaseEvent<>(outputFactory.newInstance());
// }
//
// private final LineBytesBuffer input = new LineBytesBuffer();
// private long lineNo;
// private final T output;
//
// public TwoPhaseEvent(T output) {
// this.output = output;
// }
//
// public LineBytesBuffer input() {
// return input;
// }
//
// public T output() {
// return output;
// }
//
// public TwoPhaseEvent<T> lineNo(long lineNo) {
// this.lineNo = lineNo;
// return this;
// }
//
// public long lineNo() {
// return lineNo;
// }
// }
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/ftrl/FtrlProximalRunner.java
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.lmax.disruptor.dsl.Disruptor;
import io.scaledml.core.BaseDisruptorRunner;
import io.scaledml.core.outputformats.OutputFormat;
import io.scaledml.core.TwoPhaseEvent;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
package io.scaledml.ftrl;
public class FtrlProximalRunner extends BaseDisruptorRunner {
private FtrlProximalModel model;
private Path outputForModelPath; | private OutputFormat outputFormat; |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/main/java/io/scaledml/ftrl/FtrlProximalRunner.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/BaseDisruptorRunner.java
// public abstract class BaseDisruptorRunner {
// private Disruptor<? extends TwoPhaseEvent<?>> disruptor;
// private Supplier<InputStream> inputStreamFactory;
// private boolean skipFirst;
// private Phaser phaser;
//
// public void process() throws IOException {
// try (FastBufferedInputStream stream = new FastBufferedInputStream(inputStreamFactory.get())) {
// Preconditions.checkArgument(phaser.getRegisteredParties() == 0);
// phaser.register();
// disruptor.start();
// RingBuffer<? extends TwoPhaseEvent> ringBuffer = disruptor.getRingBuffer();
// long cursor = ringBuffer.next();
// LineBytesBuffer buffer = ringBuffer.get(cursor).input();
// long lineNo = 0;
// ringBuffer.get(cursor).lineNo(lineNo);
// boolean needToSkipNext = skipFirst;
// while (buffer.readLineFrom(stream)) {
// if (needToSkipNext) {
// needToSkipNext = false;
// continue;
// }
// lineNo++;
// ringBuffer.publish(cursor);
// cursor = ringBuffer.next();
// buffer = ringBuffer.get(cursor).input();
// ringBuffer.get(cursor).lineNo(lineNo);
// }
// disruptor.shutdown();
// phaser.arriveAndAwaitAdvance();
// phaser.arriveAndDeregister();
// } finally {
// afterDisruptorProcessed();
// }
// }
//
// protected abstract void afterDisruptorProcessed() throws IOException;
//
// protected void setDisruptor(Disruptor<? extends TwoPhaseEvent<?>> disruptor) {
// this.disruptor = disruptor;
// }
//
// @Inject
// public void setInputStreamFactory(Supplier<InputStream> inputStreamFactory) {
// this.inputStreamFactory = inputStreamFactory;
// }
//
// @Inject
// public void setSkipFirst(@Named("skipFirst") boolean skipFirst) {
// this.skipFirst = skipFirst;
// }
//
// @Inject
// public void setPhaser(Phaser phaser) {
// this.phaser = phaser;
// }
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/outputformats/OutputFormat.java
// public interface OutputFormat extends Closeable {
// void emit(SparseItem item, double prediction);
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/TwoPhaseEvent.java
// public class TwoPhaseEvent<T> {
// public static <T> EventFactory<TwoPhaseEvent<T>> factory(EventFactory<T> outputFactory) {
// return () -> new TwoPhaseEvent<>(outputFactory.newInstance());
// }
//
// private final LineBytesBuffer input = new LineBytesBuffer();
// private long lineNo;
// private final T output;
//
// public TwoPhaseEvent(T output) {
// this.output = output;
// }
//
// public LineBytesBuffer input() {
// return input;
// }
//
// public T output() {
// return output;
// }
//
// public TwoPhaseEvent<T> lineNo(long lineNo) {
// this.lineNo = lineNo;
// return this;
// }
//
// public long lineNo() {
// return lineNo;
// }
// }
| import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.lmax.disruptor.dsl.Disruptor;
import io.scaledml.core.BaseDisruptorRunner;
import io.scaledml.core.outputformats.OutputFormat;
import io.scaledml.core.TwoPhaseEvent;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional; | package io.scaledml.ftrl;
public class FtrlProximalRunner extends BaseDisruptorRunner {
private FtrlProximalModel model;
private Path outputForModelPath;
private OutputFormat outputFormat;
protected void afterDisruptorProcessed() throws IOException {
outputFormat.close();
if (outputForModelPath != null) {
FtrlProximalModel.saveModel(model, outputForModelPath);
}
}
@Inject | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/BaseDisruptorRunner.java
// public abstract class BaseDisruptorRunner {
// private Disruptor<? extends TwoPhaseEvent<?>> disruptor;
// private Supplier<InputStream> inputStreamFactory;
// private boolean skipFirst;
// private Phaser phaser;
//
// public void process() throws IOException {
// try (FastBufferedInputStream stream = new FastBufferedInputStream(inputStreamFactory.get())) {
// Preconditions.checkArgument(phaser.getRegisteredParties() == 0);
// phaser.register();
// disruptor.start();
// RingBuffer<? extends TwoPhaseEvent> ringBuffer = disruptor.getRingBuffer();
// long cursor = ringBuffer.next();
// LineBytesBuffer buffer = ringBuffer.get(cursor).input();
// long lineNo = 0;
// ringBuffer.get(cursor).lineNo(lineNo);
// boolean needToSkipNext = skipFirst;
// while (buffer.readLineFrom(stream)) {
// if (needToSkipNext) {
// needToSkipNext = false;
// continue;
// }
// lineNo++;
// ringBuffer.publish(cursor);
// cursor = ringBuffer.next();
// buffer = ringBuffer.get(cursor).input();
// ringBuffer.get(cursor).lineNo(lineNo);
// }
// disruptor.shutdown();
// phaser.arriveAndAwaitAdvance();
// phaser.arriveAndDeregister();
// } finally {
// afterDisruptorProcessed();
// }
// }
//
// protected abstract void afterDisruptorProcessed() throws IOException;
//
// protected void setDisruptor(Disruptor<? extends TwoPhaseEvent<?>> disruptor) {
// this.disruptor = disruptor;
// }
//
// @Inject
// public void setInputStreamFactory(Supplier<InputStream> inputStreamFactory) {
// this.inputStreamFactory = inputStreamFactory;
// }
//
// @Inject
// public void setSkipFirst(@Named("skipFirst") boolean skipFirst) {
// this.skipFirst = skipFirst;
// }
//
// @Inject
// public void setPhaser(Phaser phaser) {
// this.phaser = phaser;
// }
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/outputformats/OutputFormat.java
// public interface OutputFormat extends Closeable {
// void emit(SparseItem item, double prediction);
// }
//
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/TwoPhaseEvent.java
// public class TwoPhaseEvent<T> {
// public static <T> EventFactory<TwoPhaseEvent<T>> factory(EventFactory<T> outputFactory) {
// return () -> new TwoPhaseEvent<>(outputFactory.newInstance());
// }
//
// private final LineBytesBuffer input = new LineBytesBuffer();
// private long lineNo;
// private final T output;
//
// public TwoPhaseEvent(T output) {
// this.output = output;
// }
//
// public LineBytesBuffer input() {
// return input;
// }
//
// public T output() {
// return output;
// }
//
// public TwoPhaseEvent<T> lineNo(long lineNo) {
// this.lineNo = lineNo;
// return this;
// }
//
// public long lineNo() {
// return lineNo;
// }
// }
// Path: fast-ftrl-proximal/src/main/java/io/scaledml/ftrl/FtrlProximalRunner.java
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.lmax.disruptor.dsl.Disruptor;
import io.scaledml.core.BaseDisruptorRunner;
import io.scaledml.core.outputformats.OutputFormat;
import io.scaledml.core.TwoPhaseEvent;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
package io.scaledml.ftrl;
public class FtrlProximalRunner extends BaseDisruptorRunner {
private FtrlProximalModel model;
private Path outputForModelPath;
private OutputFormat outputFormat;
protected void afterDisruptorProcessed() throws IOException {
outputFormat.close();
if (outputForModelPath != null) {
FtrlProximalModel.saveModel(model, outputForModelPath);
}
}
@Inject | public FtrlProximalRunner disruptor(@Named("disruptor") Disruptor<? extends TwoPhaseEvent<?>> disruptor) { |
scaled-ml/Scaled-ML | fast-ftrl-proximal/src/test/java/io/scaledml/ftrl/options/ColumnsInfoTest.java | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/inputformats/ColumnsMask.java
// public class ColumnsMask {
// private final String str;
// private ArrayList<ColumnType> columns = new ArrayList<>();
//
// public ColumnsMask(String str) {
// this.str = str;
// char[] arr = str.toCharArray();
// State state = State.OUT_OF_BRACKET;
// StringBuilder sb = new StringBuilder();
// for (char c : arr) {
// switch (state) {
// case OUT_OF_BRACKET:
// switch (c) {
// case 'l':
// case 'i':
// case 'n':
// case 'c':
// columns.add(charToColumnType(c));
// break;
// case '[':
// state = State.IN_BRACKET;
// break;
// default:
// throw new IllegalArgumentException();
// }
// break;
// case IN_BRACKET:
// switch (c) {
// case '1':
// case '2':
// case '3':
// case '4':
// case '5':
// case '6':
// case '7':
// case '8':
// case '9':
// case '0':
// sb.append(c);
// break;
// case ']':
// int repeats = Integer.parseInt(sb.toString()) - 1;
// ColumnType last = columns.get(columns.size() - 1);
// for (int i = 0; i < repeats; i++) {
// columns.add(last);
// }
// sb.setLength(0);
// state = State.OUT_OF_BRACKET;
// break;
// default:
// throw new IllegalArgumentException();
// }
// break;
// }
//
// }
// }
//
// private static ColumnType charToColumnType(char c) {
// switch (c) {
// case 'l':
// return ColumnType.LABEL;
// case 'i':
// return ColumnType.ID;
// case 'n':
// return ColumnType.NUMERICAL;
// case 'c':
// return ColumnType.CATEGORICAL;
// default:
// throw new IllegalArgumentException("" + c);
// }
// }
//
// @Override
// public String toString() {
// return str;
// }
//
// public ColumnType getCategory(int colNumber) {
// if (colNumber < columns.size()) {
// return columns.get(colNumber);
// }
// return columns.get(columns.size() - 1);
// }
//
// public static enum ColumnType {
// LABEL,
// ID,
// NUMERICAL,
// CATEGORICAL
// }
//
// private static enum State {
// IN_BRACKET, OUT_OF_BRACKET
// }
//
//
// }
| import io.scaledml.core.inputformats.ColumnsMask;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals; | package io.scaledml.ftrl.options;
public class ColumnsInfoTest {
@Test
public void parsesLongMask() { | // Path: fast-ftrl-proximal/src/main/java/io/scaledml/core/inputformats/ColumnsMask.java
// public class ColumnsMask {
// private final String str;
// private ArrayList<ColumnType> columns = new ArrayList<>();
//
// public ColumnsMask(String str) {
// this.str = str;
// char[] arr = str.toCharArray();
// State state = State.OUT_OF_BRACKET;
// StringBuilder sb = new StringBuilder();
// for (char c : arr) {
// switch (state) {
// case OUT_OF_BRACKET:
// switch (c) {
// case 'l':
// case 'i':
// case 'n':
// case 'c':
// columns.add(charToColumnType(c));
// break;
// case '[':
// state = State.IN_BRACKET;
// break;
// default:
// throw new IllegalArgumentException();
// }
// break;
// case IN_BRACKET:
// switch (c) {
// case '1':
// case '2':
// case '3':
// case '4':
// case '5':
// case '6':
// case '7':
// case '8':
// case '9':
// case '0':
// sb.append(c);
// break;
// case ']':
// int repeats = Integer.parseInt(sb.toString()) - 1;
// ColumnType last = columns.get(columns.size() - 1);
// for (int i = 0; i < repeats; i++) {
// columns.add(last);
// }
// sb.setLength(0);
// state = State.OUT_OF_BRACKET;
// break;
// default:
// throw new IllegalArgumentException();
// }
// break;
// }
//
// }
// }
//
// private static ColumnType charToColumnType(char c) {
// switch (c) {
// case 'l':
// return ColumnType.LABEL;
// case 'i':
// return ColumnType.ID;
// case 'n':
// return ColumnType.NUMERICAL;
// case 'c':
// return ColumnType.CATEGORICAL;
// default:
// throw new IllegalArgumentException("" + c);
// }
// }
//
// @Override
// public String toString() {
// return str;
// }
//
// public ColumnType getCategory(int colNumber) {
// if (colNumber < columns.size()) {
// return columns.get(colNumber);
// }
// return columns.get(columns.size() - 1);
// }
//
// public static enum ColumnType {
// LABEL,
// ID,
// NUMERICAL,
// CATEGORICAL
// }
//
// private static enum State {
// IN_BRACKET, OUT_OF_BRACKET
// }
//
//
// }
// Path: fast-ftrl-proximal/src/test/java/io/scaledml/ftrl/options/ColumnsInfoTest.java
import io.scaledml.core.inputformats.ColumnsMask;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
package io.scaledml.ftrl.options;
public class ColumnsInfoTest {
@Test
public void parsesLongMask() { | ColumnsMask ilcnn = new ColumnsMask("ilcnn"); |
tsenger/animamea | animamea/src/de/tsenger/animamea/ta/TerminalAuthentication.java | // Path: animamea/src/de/tsenger/animamea/asn1/DomainParameter.java
// public class DomainParameter {
//
// private DHParameters dhParameters = null;
// private ECParameterSpec ecSpec = null;
//
// /**
// * Extrahiert aus dem AlogorithmIdentifier standardisierte Parameter für DH oder ECDH.
// * @param Referenz auf Standardized Domain Parameters
// */
// public DomainParameter(int ref) {
// if (ref<0||ref>18) throw new UnsupportedOperationException("unsupported standardized Domain Parameters");
// else getParameters(ref);
// }
//
// /**
// * Extrahiert aus dem AlogorithmIdentifier die Parameter für DH oder ECDH.
// * Es werden standardisierte DomainParameter und explizite DP erkannt.
// * @param algorithm OID
// */
// public DomainParameter(AlgorithmIdentifier aid) {
// if (aid.getAlgorithm().toString().equals(BSIObjectIdentifiers.standardizedDomainParameters.toString())) {
// int dpref = ((ASN1Integer)aid.getParameters()).getPositiveValue().intValue();
// getParameters(dpref);
// }
//
// else if (aid.getAlgorithm().toString().equals("1.2.840.10045.2.1")) {
// X9ECParameters x9ecp = X9ECParameters.getInstance(aid.getParameters());
// ecSpec = new ECParameterSpec(x9ecp.getCurve(), x9ecp.getG(), x9ecp.getN());
// }
//
// //TODO properitäre DH Domain Parameter
//
// else throw new UnsupportedOperationException("unsupported Domain Parameters. Algorithm OID: "+aid.getAlgorithm().toString());
// }
//
// /**
// * @param dpref
// */
// private void getParameters(int dpref) {
// switch (dpref) {
// case 0:
// dhParameters = modp1024_160();
// break;
// case 1:
// dhParameters = modp2048_224();
// break;
// case 3:
// dhParameters = modp2048_256();
// break;
// case 8:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp192r1");
// break;
// case 9:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp192r1");
// break;
// case 10:;
// ecSpec = ECNamedCurveTable.getParameterSpec("secp224r1");
// break;
// case 11:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp224r1");
// break;
// case 12:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
// break;
// case 13:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp256r1");
// break;
// case 14:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp320r1");
// break;
// case 15:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp384r1");
// break;
// case 16:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp384r1");
// break;
// case 17:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp512r1");
// break;
// case 18:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp521r1");
// break;
// }
// }
//
// public String getDPType() {
// if (ecSpec!=null) return "ECDH";
// else if (dhParameters!=null) return "DH";
// return null;
// }
//
// public ECParameterSpec getECParameter() {
// return ecSpec;
// }
//
// public DHParameters getDHParameter() {
// return dhParameters;
// }
//
// }
| import de.tsenger.animamea.asn1.DomainParameter;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.Security;
import java.util.Random;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ECParameterSpec; | /**
* Copyright 2011, Tobias Senger
*
* This file is part of animamea.
*
* Animamea 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.
*
* Animamea 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 animamea. If not, see <http://www.gnu.org/licenses/>.
*/
package de.tsenger.animamea.ta;
/**
* @author Tobias Senger (tobias@t-senger.de)
*
*/
public abstract class TerminalAuthentication {
private final SecureRandom randomGenerator = new SecureRandom();
| // Path: animamea/src/de/tsenger/animamea/asn1/DomainParameter.java
// public class DomainParameter {
//
// private DHParameters dhParameters = null;
// private ECParameterSpec ecSpec = null;
//
// /**
// * Extrahiert aus dem AlogorithmIdentifier standardisierte Parameter für DH oder ECDH.
// * @param Referenz auf Standardized Domain Parameters
// */
// public DomainParameter(int ref) {
// if (ref<0||ref>18) throw new UnsupportedOperationException("unsupported standardized Domain Parameters");
// else getParameters(ref);
// }
//
// /**
// * Extrahiert aus dem AlogorithmIdentifier die Parameter für DH oder ECDH.
// * Es werden standardisierte DomainParameter und explizite DP erkannt.
// * @param algorithm OID
// */
// public DomainParameter(AlgorithmIdentifier aid) {
// if (aid.getAlgorithm().toString().equals(BSIObjectIdentifiers.standardizedDomainParameters.toString())) {
// int dpref = ((ASN1Integer)aid.getParameters()).getPositiveValue().intValue();
// getParameters(dpref);
// }
//
// else if (aid.getAlgorithm().toString().equals("1.2.840.10045.2.1")) {
// X9ECParameters x9ecp = X9ECParameters.getInstance(aid.getParameters());
// ecSpec = new ECParameterSpec(x9ecp.getCurve(), x9ecp.getG(), x9ecp.getN());
// }
//
// //TODO properitäre DH Domain Parameter
//
// else throw new UnsupportedOperationException("unsupported Domain Parameters. Algorithm OID: "+aid.getAlgorithm().toString());
// }
//
// /**
// * @param dpref
// */
// private void getParameters(int dpref) {
// switch (dpref) {
// case 0:
// dhParameters = modp1024_160();
// break;
// case 1:
// dhParameters = modp2048_224();
// break;
// case 3:
// dhParameters = modp2048_256();
// break;
// case 8:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp192r1");
// break;
// case 9:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp192r1");
// break;
// case 10:;
// ecSpec = ECNamedCurveTable.getParameterSpec("secp224r1");
// break;
// case 11:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp224r1");
// break;
// case 12:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
// break;
// case 13:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp256r1");
// break;
// case 14:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp320r1");
// break;
// case 15:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp384r1");
// break;
// case 16:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp384r1");
// break;
// case 17:
// ecSpec = ECNamedCurveTable.getParameterSpec("brainpoolp512r1");
// break;
// case 18:
// ecSpec = ECNamedCurveTable.getParameterSpec("secp521r1");
// break;
// }
// }
//
// public String getDPType() {
// if (ecSpec!=null) return "ECDH";
// else if (dhParameters!=null) return "DH";
// return null;
// }
//
// public ECParameterSpec getECParameter() {
// return ecSpec;
// }
//
// public DHParameters getDHParameter() {
// return dhParameters;
// }
//
// }
// Path: animamea/src/de/tsenger/animamea/ta/TerminalAuthentication.java
import de.tsenger.animamea.asn1.DomainParameter;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.Security;
import java.util.Random;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ECParameterSpec;
/**
* Copyright 2011, Tobias Senger
*
* This file is part of animamea.
*
* Animamea 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.
*
* Animamea 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 animamea. If not, see <http://www.gnu.org/licenses/>.
*/
package de.tsenger.animamea.ta;
/**
* @author Tobias Senger (tobias@t-senger.de)
*
*/
public abstract class TerminalAuthentication {
private final SecureRandom randomGenerator = new SecureRandom();
| private DomainParameter caDP = null; |
tsenger/animamea | animamea/src/de/tsenger/animamea/iso7816/SecureMessaging.java | // Path: animamea/src/de/tsenger/animamea/crypto/AmCryptoException.java
// @SuppressWarnings("serial")
// public class AmCryptoException extends Exception {
//
// /**
// *
// */
// public AmCryptoException() {
// // TODO Auto-generated constructor stub
// }
//
// /**
// * @param message
// */
// public AmCryptoException(String message) {
// super(message);
// // TODO Auto-generated constructor stub
// }
//
// /**
// * @param cause
// */
// public AmCryptoException(Throwable cause) {
// super(cause);
// // TODO Auto-generated constructor stub
// }
//
// /**
// * @param message
// * @param cause
// */
// public AmCryptoException(String message, Throwable cause) {
// super(message, cause);
// // TODO Auto-generated constructor stub
// }
//
// }
| import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import org.bouncycastle.asn1.ASN1InputStream;
import de.tsenger.animamea.crypto.AmCryptoException;
import de.tsenger.animamea.crypto.AmCryptoProvider;
import de.tsenger.animamea.tools.HexString; | // occurs
// Construct K (SSC||DO87||DO99)
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try {
if (do87 != null)
bout.write(do87.getEncoded());
bout.write(do99.getEncoded());
} catch (IOException e) {
throw new SecureMessagingException(e);
}
crypto.init(ks_mac, ssc);
byte[] cc = crypto.getMAC(bout.toByteArray());
byte[] do8eData = do8E.getData();
if (!java.util.Arrays.equals(cc, do8eData))
throw new SecureMessagingException("Checksum is incorrect!\n Calculated CC: " + HexString.bufferToHex(cc) + "\nCC in DO8E: "
+ HexString.bufferToHex(do8eData));
// Decrypt DO87
byte[] data = null;
byte[] unwrappedAPDUBytes = null;
if (do87 != null) {
crypto.init(ks_enc, ssc);
byte[] do87Data = do87.getData();
try {
data = crypto.decrypt(do87Data); | // Path: animamea/src/de/tsenger/animamea/crypto/AmCryptoException.java
// @SuppressWarnings("serial")
// public class AmCryptoException extends Exception {
//
// /**
// *
// */
// public AmCryptoException() {
// // TODO Auto-generated constructor stub
// }
//
// /**
// * @param message
// */
// public AmCryptoException(String message) {
// super(message);
// // TODO Auto-generated constructor stub
// }
//
// /**
// * @param cause
// */
// public AmCryptoException(Throwable cause) {
// super(cause);
// // TODO Auto-generated constructor stub
// }
//
// /**
// * @param message
// * @param cause
// */
// public AmCryptoException(String message, Throwable cause) {
// super(message, cause);
// // TODO Auto-generated constructor stub
// }
//
// }
// Path: animamea/src/de/tsenger/animamea/iso7816/SecureMessaging.java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import org.bouncycastle.asn1.ASN1InputStream;
import de.tsenger.animamea.crypto.AmCryptoException;
import de.tsenger.animamea.crypto.AmCryptoProvider;
import de.tsenger.animamea.tools.HexString;
// occurs
// Construct K (SSC||DO87||DO99)
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try {
if (do87 != null)
bout.write(do87.getEncoded());
bout.write(do99.getEncoded());
} catch (IOException e) {
throw new SecureMessagingException(e);
}
crypto.init(ks_mac, ssc);
byte[] cc = crypto.getMAC(bout.toByteArray());
byte[] do8eData = do8E.getData();
if (!java.util.Arrays.equals(cc, do8eData))
throw new SecureMessagingException("Checksum is incorrect!\n Calculated CC: " + HexString.bufferToHex(cc) + "\nCC in DO8E: "
+ HexString.bufferToHex(do8eData));
// Decrypt DO87
byte[] data = null;
byte[] unwrappedAPDUBytes = null;
if (do87 != null) {
crypto.init(ks_enc, ssc);
byte[] do87Data = do87.getData();
try {
data = crypto.decrypt(do87Data); | } catch (AmCryptoException e) { |
tsenger/animamea | animamea/src/de/tsenger/animamea/iso7816/MSESetAT.java | // Path: animamea/src/de/tsenger/animamea/asn1/CertificateHolderAuthorizationTemplate.java
// public class CertificateHolderAuthorizationTemplate extends ASN1Object{
//
// private ASN1ObjectIdentifier terminalType = null;
// private DiscretionaryData auth = null;
// private byte role;
//
// /** Constructor for Encoding a CHAT
// * @param terminalType OID for the terminal type to use
// * @param disData
// */
// public CertificateHolderAuthorizationTemplate(ASN1ObjectIdentifier terminalType, DiscretionaryData disData) {
// this.terminalType = terminalType;
// this.auth = disData;
// }
//
// /** Constructor for Decoding CHAT from SEQUENCE
// * @param chatSeq
// * @throws IOException
// */
// public CertificateHolderAuthorizationTemplate(ASN1Sequence chatSeq) throws IOException {
// this.terminalType = (ASN1ObjectIdentifier) chatSeq.getObjectAt(0);
//
// DEROctetString oct = (DEROctetString) ((DERApplicationSpecific) chatSeq.getObjectAt(1)).getObject(BERTags.OCTET_STRING);
// this.auth = new DiscretionaryData(oct.getOctets());
//
// }
//
//
//
// public byte getRole(){
// this.role = (byte) (auth.getData()[0] & 0xc0);
// return role;
// }
//
// /* (non-Javadoc)
// * @see org.bouncycastle.asn1.ASN1Object#toASN1Primitive()
// */
// @Override
// public ASN1Primitive toASN1Primitive() {
// ASN1EncodableVector v = new ASN1EncodableVector();
// v.add(terminalType);
// v.add(auth);
//
// return new DERApplicationSpecific(0x4c, v);
// }
//
//
// }
| import de.tsenger.animamea.asn1.CertificateHolderAuthorizationTemplate;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.smartcardio.CommandAPDU;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERTaggedObject; | } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setAuxiliaryAuthenticatedData() throws UnsupportedOperationException {
// TODO noch zu implementieren, Tag 0x67
throw new UnsupportedOperationException("setAuxiliaryAuthenticationData not yet implemented!");
}
/**
* Setzt das Tag 0x91 (Ephemeral Public Key). Der PK muss bereits komprimiert
* (siehe comp()-Funktion in TR-03110) sein.
* @param pubKey comp(ephemeral PK_PCD) -> TR-03110 A.2.2.3
*/
public void setEphemeralPublicKey(byte[] pubKey) {
DERTaggedObject to = new DERTaggedObject(false, 0x11, new DEROctetString(pubKey));
try {
do91EphemeralPublicKEy = to.getEncoded(ASN1Encoding.DER);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param chat
*/ | // Path: animamea/src/de/tsenger/animamea/asn1/CertificateHolderAuthorizationTemplate.java
// public class CertificateHolderAuthorizationTemplate extends ASN1Object{
//
// private ASN1ObjectIdentifier terminalType = null;
// private DiscretionaryData auth = null;
// private byte role;
//
// /** Constructor for Encoding a CHAT
// * @param terminalType OID for the terminal type to use
// * @param disData
// */
// public CertificateHolderAuthorizationTemplate(ASN1ObjectIdentifier terminalType, DiscretionaryData disData) {
// this.terminalType = terminalType;
// this.auth = disData;
// }
//
// /** Constructor for Decoding CHAT from SEQUENCE
// * @param chatSeq
// * @throws IOException
// */
// public CertificateHolderAuthorizationTemplate(ASN1Sequence chatSeq) throws IOException {
// this.terminalType = (ASN1ObjectIdentifier) chatSeq.getObjectAt(0);
//
// DEROctetString oct = (DEROctetString) ((DERApplicationSpecific) chatSeq.getObjectAt(1)).getObject(BERTags.OCTET_STRING);
// this.auth = new DiscretionaryData(oct.getOctets());
//
// }
//
//
//
// public byte getRole(){
// this.role = (byte) (auth.getData()[0] & 0xc0);
// return role;
// }
//
// /* (non-Javadoc)
// * @see org.bouncycastle.asn1.ASN1Object#toASN1Primitive()
// */
// @Override
// public ASN1Primitive toASN1Primitive() {
// ASN1EncodableVector v = new ASN1EncodableVector();
// v.add(terminalType);
// v.add(auth);
//
// return new DERApplicationSpecific(0x4c, v);
// }
//
//
// }
// Path: animamea/src/de/tsenger/animamea/iso7816/MSESetAT.java
import de.tsenger.animamea.asn1.CertificateHolderAuthorizationTemplate;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.smartcardio.CommandAPDU;
import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERTaggedObject;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setAuxiliaryAuthenticatedData() throws UnsupportedOperationException {
// TODO noch zu implementieren, Tag 0x67
throw new UnsupportedOperationException("setAuxiliaryAuthenticationData not yet implemented!");
}
/**
* Setzt das Tag 0x91 (Ephemeral Public Key). Der PK muss bereits komprimiert
* (siehe comp()-Funktion in TR-03110) sein.
* @param pubKey comp(ephemeral PK_PCD) -> TR-03110 A.2.2.3
*/
public void setEphemeralPublicKey(byte[] pubKey) {
DERTaggedObject to = new DERTaggedObject(false, 0x11, new DEROctetString(pubKey));
try {
do91EphemeralPublicKEy = to.getEncoded(ASN1Encoding.DER);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param chat
*/ | public void setCHAT(CertificateHolderAuthorizationTemplate chat) { |
peterfuture/dttv-android | dttv/dttv-samples/src/main/java/dttv/app/adapter/FileAdapter.java | // Path: dttv/dttv-samples/src/main/java/dttv/app/model/Item.java
// public class Item extends File {
//
// private static final long serialVersionUID = 1L;
//
// public Item(File dir, String name) {
// super(dir, name);
// this.file = name;
// // TODO Auto-generated constructor stub
// }
//
// public String file;
// private int icon;
//
// public int getIcon() {
// return icon;
// }
//
// public void setIcon(int icon) {
// this.icon = icon;
// }
//
// @Override
// public String toString() {
// return file;
// }
// }
| import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import dttv.app.R;
import dttv.app.model.Item;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView; | package dttv.app.adapter;
@SuppressLint("SimpleDateFormat")
public class FileAdapter extends BaseAdapter {
private LayoutInflater inflater; | // Path: dttv/dttv-samples/src/main/java/dttv/app/model/Item.java
// public class Item extends File {
//
// private static final long serialVersionUID = 1L;
//
// public Item(File dir, String name) {
// super(dir, name);
// this.file = name;
// // TODO Auto-generated constructor stub
// }
//
// public String file;
// private int icon;
//
// public int getIcon() {
// return icon;
// }
//
// public void setIcon(int icon) {
// this.icon = icon;
// }
//
// @Override
// public String toString() {
// return file;
// }
// }
// Path: dttv/dttv-samples/src/main/java/dttv/app/adapter/FileAdapter.java
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import dttv.app.R;
import dttv.app.model.Item;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
package dttv.app.adapter;
@SuppressLint("SimpleDateFormat")
public class FileAdapter extends BaseAdapter {
private LayoutInflater inflater; | private List<Item> mList; |
peterfuture/dttv-android | dttv/dttv-samples/src/main/java/dttv/app/base/SimpleActivity.java | // Path: dttv/dttv-samples/src/main/java/dttv/app/AppApplication.java
// public class AppApplication extends Application {
//
// private static Context mContext;
// public static String filePath = android.os.Environment.getExternalStorageDirectory()+"/dttv";
//
// private static AppApplication instance;
// private Set<Activity> allActivities;
//
// public static int SCREEN_WIDTH = -1;
// public static int SCREEN_HEIGHT = -1;
// public static float DIMEN_RATE = -1.0F;
// public static int DIMEN_DPI = -1;
//
// public static synchronized AppApplication getInstance() {
// return instance;
// }
//
// static {
// AppCompatDelegate.setDefaultNightMode(
// AppCompatDelegate.MODE_NIGHT_NO);
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// this.mContext = this;
// instance = this;
//
// //初始化屏幕宽高
// getScreenSize();
//
// //CrashHandler.getInstance().init(this);//初始化全局异常管理
// new Thread(new Runnable() {
// @Override
// public void run() {
// writeToSdCard();
// }
// }).start();
// }
//
//
//
// private void writeToSdCard(){
// if (isExist()){
// return;
// }
// boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
// if (sdCardExist){
// try {
// InputStream sdpInStream = getClass().getResourceAsStream("/assets/tower.sdp");
// if (sdpInStream == null){
// throw new IOException("未加载sdp文件");
// }
// File file = new File(filePath);
// if (!file.exists()){
// file.mkdirs();
// }
// FileOutputStream outputStream = new FileOutputStream(filePath + "/tower.sdp");
// byte[] buffer = new byte[512];
// int count = 0;
// while ((count = sdpInStream.read(buffer)) > 0){
// outputStream.write(buffer,0,count);
// }
// outputStream.flush();
// outputStream.close();
// sdpInStream.close();
// }catch (IOException e){
// e.printStackTrace();
// }
// }
// }
//
// private boolean isExist() {
// File file = new File(filePath + "/tower.sdp");
// if (file.exists()) {
// return true;
// } else {
// return false;
// }
// }
//
// public static Context getContext(){
// return mContext;
// }
//
// protected void attachBaseContext(Context base) {
// super.attachBaseContext(base);
// MultiDex.install(this);
// }
//
// public void addActivity(Activity act) {
// if (allActivities == null) {
// allActivities = new HashSet<>();
// }
// allActivities.add(act);
// }
//
// public void removeActivity(Activity act) {
// if (allActivities != null) {
// allActivities.remove(act);
// }
// }
//
// public void exitApp() {
// if (allActivities != null) {
// synchronized (allActivities) {
// for (Activity act : allActivities) {
// act.finish();
// }
// }
// }
// android.os.Process.killProcess(android.os.Process.myPid());
// System.exit(0);
// }
//
// public void getScreenSize() {
// WindowManager windowManager = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
// DisplayMetrics dm = new DisplayMetrics();
// Display display = windowManager.getDefaultDisplay();
// display.getMetrics(dm);
// DIMEN_RATE = dm.density / 1.0F;
// DIMEN_DPI = dm.densityDpi;
// SCREEN_WIDTH = dm.widthPixels;
// SCREEN_HEIGHT = dm.heightPixels;
// if(SCREEN_WIDTH > SCREEN_HEIGHT) {
// int t = SCREEN_HEIGHT;
// SCREEN_HEIGHT = SCREEN_WIDTH;
// SCREEN_WIDTH = t;
// }
// }
// }
| import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import dttv.app.AppApplication;
import me.yokeyword.fragmentation.SupportActivity; | package dttv.app.base;
/**
*
* 无MVP的activity基类
*/
public abstract class SimpleActivity extends SupportActivity {
protected Activity mContext;
private Unbinder mUnBinder;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayout());
mUnBinder = ButterKnife.bind(this);
mContext = this; | // Path: dttv/dttv-samples/src/main/java/dttv/app/AppApplication.java
// public class AppApplication extends Application {
//
// private static Context mContext;
// public static String filePath = android.os.Environment.getExternalStorageDirectory()+"/dttv";
//
// private static AppApplication instance;
// private Set<Activity> allActivities;
//
// public static int SCREEN_WIDTH = -1;
// public static int SCREEN_HEIGHT = -1;
// public static float DIMEN_RATE = -1.0F;
// public static int DIMEN_DPI = -1;
//
// public static synchronized AppApplication getInstance() {
// return instance;
// }
//
// static {
// AppCompatDelegate.setDefaultNightMode(
// AppCompatDelegate.MODE_NIGHT_NO);
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// this.mContext = this;
// instance = this;
//
// //初始化屏幕宽高
// getScreenSize();
//
// //CrashHandler.getInstance().init(this);//初始化全局异常管理
// new Thread(new Runnable() {
// @Override
// public void run() {
// writeToSdCard();
// }
// }).start();
// }
//
//
//
// private void writeToSdCard(){
// if (isExist()){
// return;
// }
// boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
// if (sdCardExist){
// try {
// InputStream sdpInStream = getClass().getResourceAsStream("/assets/tower.sdp");
// if (sdpInStream == null){
// throw new IOException("未加载sdp文件");
// }
// File file = new File(filePath);
// if (!file.exists()){
// file.mkdirs();
// }
// FileOutputStream outputStream = new FileOutputStream(filePath + "/tower.sdp");
// byte[] buffer = new byte[512];
// int count = 0;
// while ((count = sdpInStream.read(buffer)) > 0){
// outputStream.write(buffer,0,count);
// }
// outputStream.flush();
// outputStream.close();
// sdpInStream.close();
// }catch (IOException e){
// e.printStackTrace();
// }
// }
// }
//
// private boolean isExist() {
// File file = new File(filePath + "/tower.sdp");
// if (file.exists()) {
// return true;
// } else {
// return false;
// }
// }
//
// public static Context getContext(){
// return mContext;
// }
//
// protected void attachBaseContext(Context base) {
// super.attachBaseContext(base);
// MultiDex.install(this);
// }
//
// public void addActivity(Activity act) {
// if (allActivities == null) {
// allActivities = new HashSet<>();
// }
// allActivities.add(act);
// }
//
// public void removeActivity(Activity act) {
// if (allActivities != null) {
// allActivities.remove(act);
// }
// }
//
// public void exitApp() {
// if (allActivities != null) {
// synchronized (allActivities) {
// for (Activity act : allActivities) {
// act.finish();
// }
// }
// }
// android.os.Process.killProcess(android.os.Process.myPid());
// System.exit(0);
// }
//
// public void getScreenSize() {
// WindowManager windowManager = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
// DisplayMetrics dm = new DisplayMetrics();
// Display display = windowManager.getDefaultDisplay();
// display.getMetrics(dm);
// DIMEN_RATE = dm.density / 1.0F;
// DIMEN_DPI = dm.densityDpi;
// SCREEN_WIDTH = dm.widthPixels;
// SCREEN_HEIGHT = dm.heightPixels;
// if(SCREEN_WIDTH > SCREEN_HEIGHT) {
// int t = SCREEN_HEIGHT;
// SCREEN_HEIGHT = SCREEN_WIDTH;
// SCREEN_WIDTH = t;
// }
// }
// }
// Path: dttv/dttv-samples/src/main/java/dttv/app/base/SimpleActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import dttv.app.AppApplication;
import me.yokeyword.fragmentation.SupportActivity;
package dttv.app.base;
/**
*
* 无MVP的activity基类
*/
public abstract class SimpleActivity extends SupportActivity {
protected Activity mContext;
private Unbinder mUnBinder;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayout());
mUnBinder = ButterKnife.bind(this);
mContext = this; | AppApplication.getInstance().addActivity(this); |
peterfuture/dttv-android | dttv/dttv-samples/src/main/java/dttv/app/widget/SlideTabsFragment.java | // Path: dttv/dttv-samples/src/main/java/dttv/app/impl/I_KeyIntercept.java
// public interface I_KeyIntercept {
// public boolean isNeedIntercept(boolean isNeed);
// }
//
// Path: dttv/dttv-samples/src/main/java/dttv/app/impl/I_OnMyKey.java
// public interface I_OnMyKey {
// public void myOnKeyDown(int keyCode);
// }
//
// Path: dttv/dttv-samples/src/main/java/dttv/app/utils/Constant.java
// public class Constant {
//
// public final static String EXTRA_MESSAGE = "com.example.simpleplayer.MESSAGE";
// public final static String FILE_MSG = "dttp.app.media.URL";
// public final static String FILE_TYPE = "dttp.app.media.type";
// public static final String LOGTAG = "DTTV";
//
//
// public final static int REFRESH_TIME_MSG = 0x1000;
// public final static int BEGIN_MEDIA_MSG = REFRESH_TIME_MSG + 1;
// public final static int HIDE_OPREATE_BAR_MSG = BEGIN_MEDIA_MSG + 1;
// public final static int HIDE_PROGRESS_BAR_MSG = HIDE_OPREATE_BAR_MSG + 1;
// public final static int REFRESH_TIME = 1000;
//
//
// public static final String ARGUMENTS_NAME = "arg";
// public static final int LOCAL_VIDEO = 0;
// public static final int LOCAL_AUDIO = 1;
// public static final int LOCAL_FILE = 2;
//
// public static final String MEIDA_NAME_STR = "dttv.app.media_name";
//
// public static final String[] gEqulizerPresets = {
// "Normal",
// "Classical",
// "Dance",
// "Flat",
// "Folk",
// "Heavy Metal",
// "Hip Hop",
// "Jazz",
// "Rock"
// };
//
// public static final int FILTER_SIZE = 1 * 1024 * 1024;// 1MB
// public static final int FILTER_DURATION = 1 * 60 * 1000;// 1分钟
//
//
// // setting
// public static final String KEY_SETTING_FILTER_AUDIO_FILTER = "key_checkbox_setting_audio_filter";
// public static final String KEY_SETTING_FILTER_VIDEO_FILTER = "key_checkbox_setting_video_filter";
// public static final String KEY_SETTING_DECODER_TYPE = "key_listpreference_setting_decoder_type";
// public static final String KEY_SETTING_DECODER_TYPE_SOFT = "0";
// public static final String KEY_SETTING_DECODER_TYPE_HW = "1";
// public static final String KEY_SETTING_BROWSER_MODE ="key_listpreference_filebrowser_display";
// public static final String KEY_SETTING_DISPLAY_MODE ="key_listpreference_setting_display_mode";
//
// }
| import dttv.app.R;
import dttv.app.impl.I_KeyIntercept;
import dttv.app.impl.I_OnMyKey;
import dttv.app.utils.Constant;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TabWidget;
import android.widget.TextView;
| package dttv.app.widget;
@SuppressLint("ValidFragment")
public class SlideTabsFragment extends Fragment implements I_OnMyKey {
private static final String TAG = "SlideTabsFragment";
private View mRootView;
private ViewPager mViewPager;
private PagerAdapter mPagerAdapter;
private TabWidget mTabWidget;
private String[] addresses = {"first", "second", "third"};
private TextView[] mTextTabs = new TextView[addresses.length];
private Context mContext;
private int currentIndicatorLeft = 0;
private ImageView iv_nav_indicator;
private int indicatorWidth = 0;
private ChangeActionModeListener mChangeActionModeListener;
| // Path: dttv/dttv-samples/src/main/java/dttv/app/impl/I_KeyIntercept.java
// public interface I_KeyIntercept {
// public boolean isNeedIntercept(boolean isNeed);
// }
//
// Path: dttv/dttv-samples/src/main/java/dttv/app/impl/I_OnMyKey.java
// public interface I_OnMyKey {
// public void myOnKeyDown(int keyCode);
// }
//
// Path: dttv/dttv-samples/src/main/java/dttv/app/utils/Constant.java
// public class Constant {
//
// public final static String EXTRA_MESSAGE = "com.example.simpleplayer.MESSAGE";
// public final static String FILE_MSG = "dttp.app.media.URL";
// public final static String FILE_TYPE = "dttp.app.media.type";
// public static final String LOGTAG = "DTTV";
//
//
// public final static int REFRESH_TIME_MSG = 0x1000;
// public final static int BEGIN_MEDIA_MSG = REFRESH_TIME_MSG + 1;
// public final static int HIDE_OPREATE_BAR_MSG = BEGIN_MEDIA_MSG + 1;
// public final static int HIDE_PROGRESS_BAR_MSG = HIDE_OPREATE_BAR_MSG + 1;
// public final static int REFRESH_TIME = 1000;
//
//
// public static final String ARGUMENTS_NAME = "arg";
// public static final int LOCAL_VIDEO = 0;
// public static final int LOCAL_AUDIO = 1;
// public static final int LOCAL_FILE = 2;
//
// public static final String MEIDA_NAME_STR = "dttv.app.media_name";
//
// public static final String[] gEqulizerPresets = {
// "Normal",
// "Classical",
// "Dance",
// "Flat",
// "Folk",
// "Heavy Metal",
// "Hip Hop",
// "Jazz",
// "Rock"
// };
//
// public static final int FILTER_SIZE = 1 * 1024 * 1024;// 1MB
// public static final int FILTER_DURATION = 1 * 60 * 1000;// 1分钟
//
//
// // setting
// public static final String KEY_SETTING_FILTER_AUDIO_FILTER = "key_checkbox_setting_audio_filter";
// public static final String KEY_SETTING_FILTER_VIDEO_FILTER = "key_checkbox_setting_video_filter";
// public static final String KEY_SETTING_DECODER_TYPE = "key_listpreference_setting_decoder_type";
// public static final String KEY_SETTING_DECODER_TYPE_SOFT = "0";
// public static final String KEY_SETTING_DECODER_TYPE_HW = "1";
// public static final String KEY_SETTING_BROWSER_MODE ="key_listpreference_filebrowser_display";
// public static final String KEY_SETTING_DISPLAY_MODE ="key_listpreference_setting_display_mode";
//
// }
// Path: dttv/dttv-samples/src/main/java/dttv/app/widget/SlideTabsFragment.java
import dttv.app.R;
import dttv.app.impl.I_KeyIntercept;
import dttv.app.impl.I_OnMyKey;
import dttv.app.utils.Constant;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TabWidget;
import android.widget.TextView;
package dttv.app.widget;
@SuppressLint("ValidFragment")
public class SlideTabsFragment extends Fragment implements I_OnMyKey {
private static final String TAG = "SlideTabsFragment";
private View mRootView;
private ViewPager mViewPager;
private PagerAdapter mPagerAdapter;
private TabWidget mTabWidget;
private String[] addresses = {"first", "second", "third"};
private TextView[] mTextTabs = new TextView[addresses.length];
private Context mContext;
private int currentIndicatorLeft = 0;
private ImageView iv_nav_indicator;
private int indicatorWidth = 0;
private ChangeActionModeListener mChangeActionModeListener;
| private I_KeyIntercept mIntercept;
|
peterfuture/dttv-android | dttv/dttv-samples/src/main/java/dttv/app/widget/SlideTabsFragment.java | // Path: dttv/dttv-samples/src/main/java/dttv/app/impl/I_KeyIntercept.java
// public interface I_KeyIntercept {
// public boolean isNeedIntercept(boolean isNeed);
// }
//
// Path: dttv/dttv-samples/src/main/java/dttv/app/impl/I_OnMyKey.java
// public interface I_OnMyKey {
// public void myOnKeyDown(int keyCode);
// }
//
// Path: dttv/dttv-samples/src/main/java/dttv/app/utils/Constant.java
// public class Constant {
//
// public final static String EXTRA_MESSAGE = "com.example.simpleplayer.MESSAGE";
// public final static String FILE_MSG = "dttp.app.media.URL";
// public final static String FILE_TYPE = "dttp.app.media.type";
// public static final String LOGTAG = "DTTV";
//
//
// public final static int REFRESH_TIME_MSG = 0x1000;
// public final static int BEGIN_MEDIA_MSG = REFRESH_TIME_MSG + 1;
// public final static int HIDE_OPREATE_BAR_MSG = BEGIN_MEDIA_MSG + 1;
// public final static int HIDE_PROGRESS_BAR_MSG = HIDE_OPREATE_BAR_MSG + 1;
// public final static int REFRESH_TIME = 1000;
//
//
// public static final String ARGUMENTS_NAME = "arg";
// public static final int LOCAL_VIDEO = 0;
// public static final int LOCAL_AUDIO = 1;
// public static final int LOCAL_FILE = 2;
//
// public static final String MEIDA_NAME_STR = "dttv.app.media_name";
//
// public static final String[] gEqulizerPresets = {
// "Normal",
// "Classical",
// "Dance",
// "Flat",
// "Folk",
// "Heavy Metal",
// "Hip Hop",
// "Jazz",
// "Rock"
// };
//
// public static final int FILTER_SIZE = 1 * 1024 * 1024;// 1MB
// public static final int FILTER_DURATION = 1 * 60 * 1000;// 1分钟
//
//
// // setting
// public static final String KEY_SETTING_FILTER_AUDIO_FILTER = "key_checkbox_setting_audio_filter";
// public static final String KEY_SETTING_FILTER_VIDEO_FILTER = "key_checkbox_setting_video_filter";
// public static final String KEY_SETTING_DECODER_TYPE = "key_listpreference_setting_decoder_type";
// public static final String KEY_SETTING_DECODER_TYPE_SOFT = "0";
// public static final String KEY_SETTING_DECODER_TYPE_HW = "1";
// public static final String KEY_SETTING_BROWSER_MODE ="key_listpreference_filebrowser_display";
// public static final String KEY_SETTING_DISPLAY_MODE ="key_listpreference_setting_display_mode";
//
// }
| import dttv.app.R;
import dttv.app.impl.I_KeyIntercept;
import dttv.app.impl.I_OnMyKey;
import dttv.app.utils.Constant;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TabWidget;
import android.widget.TextView;
| animation.setFillAfter(true);
iv_nav_indicator.setAnimation(animation);
currentIndicatorLeft = v.getLeft();*/
//isUser = true;
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
};
Fragment ft = null;
private class MyPagerAdapter extends FragmentStatePagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
//Fragment ft = null;
switch (position) {
case 0:
ft = new VideoUIFragment();
Bundle args = new Bundle();
| // Path: dttv/dttv-samples/src/main/java/dttv/app/impl/I_KeyIntercept.java
// public interface I_KeyIntercept {
// public boolean isNeedIntercept(boolean isNeed);
// }
//
// Path: dttv/dttv-samples/src/main/java/dttv/app/impl/I_OnMyKey.java
// public interface I_OnMyKey {
// public void myOnKeyDown(int keyCode);
// }
//
// Path: dttv/dttv-samples/src/main/java/dttv/app/utils/Constant.java
// public class Constant {
//
// public final static String EXTRA_MESSAGE = "com.example.simpleplayer.MESSAGE";
// public final static String FILE_MSG = "dttp.app.media.URL";
// public final static String FILE_TYPE = "dttp.app.media.type";
// public static final String LOGTAG = "DTTV";
//
//
// public final static int REFRESH_TIME_MSG = 0x1000;
// public final static int BEGIN_MEDIA_MSG = REFRESH_TIME_MSG + 1;
// public final static int HIDE_OPREATE_BAR_MSG = BEGIN_MEDIA_MSG + 1;
// public final static int HIDE_PROGRESS_BAR_MSG = HIDE_OPREATE_BAR_MSG + 1;
// public final static int REFRESH_TIME = 1000;
//
//
// public static final String ARGUMENTS_NAME = "arg";
// public static final int LOCAL_VIDEO = 0;
// public static final int LOCAL_AUDIO = 1;
// public static final int LOCAL_FILE = 2;
//
// public static final String MEIDA_NAME_STR = "dttv.app.media_name";
//
// public static final String[] gEqulizerPresets = {
// "Normal",
// "Classical",
// "Dance",
// "Flat",
// "Folk",
// "Heavy Metal",
// "Hip Hop",
// "Jazz",
// "Rock"
// };
//
// public static final int FILTER_SIZE = 1 * 1024 * 1024;// 1MB
// public static final int FILTER_DURATION = 1 * 60 * 1000;// 1分钟
//
//
// // setting
// public static final String KEY_SETTING_FILTER_AUDIO_FILTER = "key_checkbox_setting_audio_filter";
// public static final String KEY_SETTING_FILTER_VIDEO_FILTER = "key_checkbox_setting_video_filter";
// public static final String KEY_SETTING_DECODER_TYPE = "key_listpreference_setting_decoder_type";
// public static final String KEY_SETTING_DECODER_TYPE_SOFT = "0";
// public static final String KEY_SETTING_DECODER_TYPE_HW = "1";
// public static final String KEY_SETTING_BROWSER_MODE ="key_listpreference_filebrowser_display";
// public static final String KEY_SETTING_DISPLAY_MODE ="key_listpreference_setting_display_mode";
//
// }
// Path: dttv/dttv-samples/src/main/java/dttv/app/widget/SlideTabsFragment.java
import dttv.app.R;
import dttv.app.impl.I_KeyIntercept;
import dttv.app.impl.I_OnMyKey;
import dttv.app.utils.Constant;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TabWidget;
import android.widget.TextView;
animation.setFillAfter(true);
iv_nav_indicator.setAnimation(animation);
currentIndicatorLeft = v.getLeft();*/
//isUser = true;
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
};
Fragment ft = null;
private class MyPagerAdapter extends FragmentStatePagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
//Fragment ft = null;
switch (position) {
case 0:
ft = new VideoUIFragment();
Bundle args = new Bundle();
| args.putString(Constant.ARGUMENTS_NAME, mTextTabs[position].getText().toString());
|
peterfuture/dttv-android | dttv/dttv-samples/src/main/java/dttv/app/SettingActivity.java | // Path: dttv/dttv-samples/src/main/java/dttv/app/utils/Constant.java
// public class Constant {
//
// public final static String EXTRA_MESSAGE = "com.example.simpleplayer.MESSAGE";
// public final static String FILE_MSG = "dttp.app.media.URL";
// public final static String FILE_TYPE = "dttp.app.media.type";
// public static final String LOGTAG = "DTTV";
//
//
// public final static int REFRESH_TIME_MSG = 0x1000;
// public final static int BEGIN_MEDIA_MSG = REFRESH_TIME_MSG + 1;
// public final static int HIDE_OPREATE_BAR_MSG = BEGIN_MEDIA_MSG + 1;
// public final static int HIDE_PROGRESS_BAR_MSG = HIDE_OPREATE_BAR_MSG + 1;
// public final static int REFRESH_TIME = 1000;
//
//
// public static final String ARGUMENTS_NAME = "arg";
// public static final int LOCAL_VIDEO = 0;
// public static final int LOCAL_AUDIO = 1;
// public static final int LOCAL_FILE = 2;
//
// public static final String MEIDA_NAME_STR = "dttv.app.media_name";
//
// public static final String[] gEqulizerPresets = {
// "Normal",
// "Classical",
// "Dance",
// "Flat",
// "Folk",
// "Heavy Metal",
// "Hip Hop",
// "Jazz",
// "Rock"
// };
//
// public static final int FILTER_SIZE = 1 * 1024 * 1024;// 1MB
// public static final int FILTER_DURATION = 1 * 60 * 1000;// 1分钟
//
//
// // setting
// public static final String KEY_SETTING_FILTER_AUDIO_FILTER = "key_checkbox_setting_audio_filter";
// public static final String KEY_SETTING_FILTER_VIDEO_FILTER = "key_checkbox_setting_video_filter";
// public static final String KEY_SETTING_DECODER_TYPE = "key_listpreference_setting_decoder_type";
// public static final String KEY_SETTING_DECODER_TYPE_SOFT = "0";
// public static final String KEY_SETTING_DECODER_TYPE_HW = "1";
// public static final String KEY_SETTING_BROWSER_MODE ="key_listpreference_filebrowser_display";
// public static final String KEY_SETTING_DISPLAY_MODE ="key_listpreference_setting_display_mode";
//
// }
| import dttv.app.utils.Constant;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
| public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Setting Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://dttv.app/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
public static class MyPreferenceFragment extends PreferenceFragment implements OnPreferenceChangeListener, OnPreferenceClickListener {
ListPreference list_decoder_type;
ListPreference list_browser_mode;
ListPreference list_display_mode;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.setting_preference);
| // Path: dttv/dttv-samples/src/main/java/dttv/app/utils/Constant.java
// public class Constant {
//
// public final static String EXTRA_MESSAGE = "com.example.simpleplayer.MESSAGE";
// public final static String FILE_MSG = "dttp.app.media.URL";
// public final static String FILE_TYPE = "dttp.app.media.type";
// public static final String LOGTAG = "DTTV";
//
//
// public final static int REFRESH_TIME_MSG = 0x1000;
// public final static int BEGIN_MEDIA_MSG = REFRESH_TIME_MSG + 1;
// public final static int HIDE_OPREATE_BAR_MSG = BEGIN_MEDIA_MSG + 1;
// public final static int HIDE_PROGRESS_BAR_MSG = HIDE_OPREATE_BAR_MSG + 1;
// public final static int REFRESH_TIME = 1000;
//
//
// public static final String ARGUMENTS_NAME = "arg";
// public static final int LOCAL_VIDEO = 0;
// public static final int LOCAL_AUDIO = 1;
// public static final int LOCAL_FILE = 2;
//
// public static final String MEIDA_NAME_STR = "dttv.app.media_name";
//
// public static final String[] gEqulizerPresets = {
// "Normal",
// "Classical",
// "Dance",
// "Flat",
// "Folk",
// "Heavy Metal",
// "Hip Hop",
// "Jazz",
// "Rock"
// };
//
// public static final int FILTER_SIZE = 1 * 1024 * 1024;// 1MB
// public static final int FILTER_DURATION = 1 * 60 * 1000;// 1分钟
//
//
// // setting
// public static final String KEY_SETTING_FILTER_AUDIO_FILTER = "key_checkbox_setting_audio_filter";
// public static final String KEY_SETTING_FILTER_VIDEO_FILTER = "key_checkbox_setting_video_filter";
// public static final String KEY_SETTING_DECODER_TYPE = "key_listpreference_setting_decoder_type";
// public static final String KEY_SETTING_DECODER_TYPE_SOFT = "0";
// public static final String KEY_SETTING_DECODER_TYPE_HW = "1";
// public static final String KEY_SETTING_BROWSER_MODE ="key_listpreference_filebrowser_display";
// public static final String KEY_SETTING_DISPLAY_MODE ="key_listpreference_setting_display_mode";
//
// }
// Path: dttv/dttv-samples/src/main/java/dttv/app/SettingActivity.java
import dttv.app.utils.Constant;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Setting Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://dttv.app/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
public static class MyPreferenceFragment extends PreferenceFragment implements OnPreferenceChangeListener, OnPreferenceClickListener {
ListPreference list_decoder_type;
ListPreference list_browser_mode;
ListPreference list_display_mode;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.setting_preference);
| list_browser_mode = (ListPreference) findPreference(Constant.KEY_SETTING_BROWSER_MODE);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.