What I want to do is save each request of an acceslog in a hashmap
, but the saving is not being done. Please someone see the fault ???
JAVA:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
public class BuscarPatrones {
static String inici = "GET / HTTP/1.1";
static String fi = "HelloWorldExample";
/**
* @param args
*/
public static void main(String[] args) {
File f = new File( "C:/Users/Marc/Desktop/access-logs.txt" );
BufferedReader entrada;
HashMap<String, ArrayList<String>> Patrones =
new HashMap<String, ArrayList<String>>();
ArrayList<String>patron=new ArrayList<String>();
ArrayList<String>p=new ArrayList<String>();
String linea="";
int cont=0;
try {
entrada = new BufferedReader( new FileReader( f ) );
while(entrada.ready()){
linea = entrada.readLine();
linea = linea.substring(linea.indexOf("+0100]") + 8);
if(!linea.contains(inici)){
patron.add(linea);
}else{
cont++;
crearpatrones(Patrones,patron,cont);
patron.clear();
}
}}catch (IOException e) {
e.printStackTrace();
}
/*
* --------------------Resultado general del programa----------------
*
* for (Entry<String, ArrayList<String>> entry : Patrones.entrySet()) {
String key = entry.getKey();
ArrayList<String> value = entry.getValue();
System.out.println(key);
System.out.println(value);
}*/
}
private static void crearpatrones(HashMap<String, ArrayList<String>> patrones, ArrayList<String> patron2,int contador) {
// TODO Auto-generated method stub
String petición="Petición";
petición= petición+contador;
//--------------Aqui accede con la info correcta---------------------
//System.out.println(petición);
//System.out.println(patron2);
patrones.put(petición,patron2);
return;
}
}
ACCESLOG:
https://mega.nz/#!mU9l3QaS!JZw7wQEqagjATFrfYgy8xkcnVzmV2nDhyt7o_6jqyaw
127.0.0.1 - - [17/Dec/2016:19:30:30 +0100] "GET / HTTP/1.1" 200 11485
127.0.0.1 - - [17/Dec/2016:19:30:31 +0100] "GET /favicon.1 HTTP/1.1" 200 21630
127.0.0.1 - - [17/Dec/2016:19:30:32 +0100] "GET /tomcat.css HTTP/1.1" 200 5926
127.0.0.1 - - [17/Dec/2016:19:30:33 +0100] "GET /tomcat.png HTTP/1.1" 200 5103
127.0.0.1 - - [17/Dec/2016:19:30:33 +0100] "GET /asf-logo.png HTTP/1.1" 200 17811
127.0.0.1 - - [17/Dec/2016:19:30:33 +0100] "GET /bg-upper.png HTTP/1.1" 200 3103
127.0.0.1 - - [17/Dec/2016:19:30:33 +0100] "GET /bg-nav.png HTTP/1.1" 200 1401
127.0.0.1 - - [17/Dec/2016:19:30:33 +0100] "GET /bg-nav.png HTTP/1.1" 200 1401
127.0.0.1 - - [17/Dec/2016:19:30:33 +0100] "-" 400 -
127.0.0.1 - - [17/Dec/2016:19:30:37 +0100] "GET /bg-middle.png HTTP/1.1" 200 1918
127.0.0.1 - - [17/Dec/2016:19:30:37 +0100] "GET /bg-button.png HTTP/1.1" 200 713
127.0.0.1 - - [17/Dec/2016:19:31:03 +0100] "GET /examples HTTP/1.1" 302 -
127.0.0.1 - - [17/Dec/2016:19:31:03 +0100] "GET /examples/ HTTP/1.1" 200 1156
127.0.0.1 - - [17/Dec/2016:19:31:05 +0100] "GET /examples/servlets HTTP/1.1" 302 -
127.0.0.1 - - [17/Dec/2016:19:31:06 +0100] "GET /examples/servlets/ HTTP/1.1" 200 6596
127.0.0.1 - - [17/Dec/2016:19:31:09 +0100] "GET /examples/servlets/images/return.gif HTTP/1.1" 200 1231
127.0.0.1 - - [17/Dec/2016:19:31:10 +0100] "GET /examples/servlets/images/code.gif HTTP/1.1" 200 292
127.0.0.1 - - [17/Dec/2016:19:31:10 +0100] "GET /examples/servlets/images/execute.gif HTTP/1.1" 200 1242
127.0.0.1 - - [17/Dec/2016:19:31:18 +0100] "GET /examples/servlets/servlet/HelloWorldExample HTTP/1.1" 200 400
127.0.0.1 - - [17/Dec/2016:19:31:59 +0100] "GET / HTTP/1.1" 200 11458
127.0.0.1 - - [17/Dec/2016:19:31:59 +0100] "GET /tomcat.css HTTP/1.1" 200 5926
127.0.0.1 - - [17/Dec/2016:19:32:00 +0100] "GET /favicon.2 HTTP/1.1" 200 21630
127.0.0.1 - - [17/Dec/2016:19:32:00 +0100] "GET /tomcat.png HTTP/1.1" 200 5103
127.0.0.1 - - [17/Dec/2016:19:32:00 +0100] "GET /asf-logo.png HTTP/1.1" 200 17811
127.0.0.1 - - [17/Dec/2016:19:32:00 +0100] "GET /bg-nav.png HTTP/1.1" 200 1401
127.0.0.1 - - [17/Dec/2016:19:32:00 +0100] "v.png HTTP/1.1 " 400 -
127.0.0.1 - - [17/Dec/2016:19:32:02 +0100] "GET /bg-upper.png HTTP/1.1" 200 3103
127.0.0.1 - - [17/Dec/2016:19:32:03 +0100] "GET /bg-middle.png HTTP/1.1" 200 1918
127.0.0.1 - - [17/Dec/2016:19:32:03 +0100] "GET /bg-button.png HTTP/1.1" 200 713
127.0.0.1 - - [17/Dec/2016:19:32:08 +0100] "GET /examples HTTP/1.1" 302 -
127.0.0.1 - - [17/Dec/2016:19:32:08 +0100] "GET /examples/ HTTP/1.1" 200 1156
127.0.0.1 - - [17/Dec/2016:19:32:11 +0100] "GET /examples/servlets HTTP/1.1" 302 -
127.0.0.1 - - [17/Dec/2016:19:32:13 +0100] "GET /examples/servlets/ HTTP/1.1" 200 6596
127.0.0.1 - - [17/Dec/2016:19:32:18 +0100] "GET /examples/servlets/images/return.gif HTTP/1.1" 200 1231
127.0.0.1 - - [17/Dec/2016:19:32:19 +0100] "GET /examples/servlets/images/code.gif HTTP/1.1" 200 292
127.0.0.1 - - [17/Dec/2016:19:32:19 +0100] "GET /examples/servlets/images/execute.gif HTTP/1.1" 200 1242
127.0.0.1 - - [17/Dec/2016:19:32:21 +0100] "GET /examples/servlets/servlet/HelloWorldExample HTTP/1.1" 200 400
127.0.0.1 - - [17/Dec/2016:19:33:04 +0100] "GET / HTTP/1.1" 200 11485
127.0.0.1 - - [17/Dec/2016:19:33:04 +0100] "GET /favicon.3 HTTP/1.1" 200 21630
127.0.0.1 - - [17/Dec/2016:19:33:05 +0100] "GET /tomcat.css HTTP/1.1" 200 5926
127.0.0.1 - - [17/Dec/2016:19:33:06 +0100] "GET /tomcat.png HTTP/1.1" 200 5103
127.0.0.1 - - [17/Dec/2016:19:33:06 +0100] "GET /bg-upper.png HTTP/1.1" 200 3103
127.0.0.1 - - [17/Dec/2016:19:33:06 +0100] "GET /asf-logo.png HTTP/1.1" 200 17811
127.0.0.1 - - [17/Dec/2016:19:33:06 +0100] "GET /bg-nav.png HTTP/1.1" 200 1401
127.0.0.1 - - [17/Dec/2016:19:33:06 +0100] "GET /bg-nav.png HTTP/1.1" 200 1401
127.0.0.1 - - [17/Dec/2016:19:33:06 +0100] "-" 400 -
127.0.0.1 - - [17/Dec/2016:19:33:08 +0100] "GET /bg-middle.png HTTP/1.1" 200 1918
127.0.0.1 - - [17/Dec/2016:19:33:08 +0100] "GET /bg-button.png HTTP/1.1" 200 713
127.0.0.1 - - [17/Dec/2016:19:33:15 +0100] "GET /examples HTTP/1.1" 302 -
127.0.0.1 - - [17/Dec/2016:19:33:15 +0100] "GET /examples/ HTTP/1.1" 200 1156
127.0.0.1 - - [17/Dec/2016:19:33:19 +0100] "GET /examples/servlets HTTP/1.1" 302 -
127.0.0.1 - - [17/Dec/2016:19:33:20 +0100] "GET /examples/servlets/ HTTP/1.1" 200 6596
127.0.0.1 - - [17/Dec/2016:19:33:21 +0100] "GET /examples/servlets/images/code.gif HTTP/1.1" 200 292
127.0.0.1 - - [17/Dec/2016:19:33:22 +0100] "GET /examples/servlets/images/return.gif HTTP/1.1" 200 1231
127.0.0.1 - - [17/Dec/2016:19:33:22 +0100] "GET /examples/servlets/images/execute.gif HTTP/1.1" 200 1242
127.0.0.1 - - [17/Dec/2016:19:33:25 +0100] "GET /examples/servlets/servlet/HelloWorldExample HTTP/1.1" 200 400