Skip to content

Instantly share code, notes, and snippets.

@jemygraw
Last active December 16, 2016 10:08
Show Gist options
  • Save jemygraw/71c2c96740ad32f3f7c3a96b1ad88e1b to your computer and use it in GitHub Desktop.
Save jemygraw/71c2c96740ad32f3f7c3a96b1ad88e1b to your computer and use it in GitHub Desktop.
qiniu-cdn-log-split.java
package com.qiniu.hadooplearn.play;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class StringTokenPlay {
public static void main(String[] args) throws IOException {
String filePath = "/Users/jemy/Temp/yimutian/img.yimutian.com_2016-11-22_part-00000";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath))));
String line = null;
while ((line = br.readLine()) != null) {
// System.out.println(line);
StringTokenizer token = new StringTokenizer(line, " ", false);
System.out.println("---------");
System.out.println("IP: " + token.nextToken());
System.out.println("None: " + token.nextToken());
System.out.println("ResponseTime: " + token.nextToken());
token.nextToken("[]");
System.out.println("TimeLocal: " + token.nextToken());
token.nextToken("\"");
System.out.println("Request:" + token.nextToken());
token.nextToken(" ");
System.out.println("Code:" + token.nextToken());
System.out.println("Size:" + token.nextToken());
token.nextToken("\"");
System.out.println("Referer:" + token.nextToken());
token.nextToken("\"");
System.out.println("UserAgent:" + token.nextToken());
// return;
}
br.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment