package com.IOFile;

import java.io.IOException;
import java.nio.file.DirectoryIteratorException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Test {
	public static void main(String[] args) {
//		listDirContents(Paths
//				.get("D:/WAndroid/BitchTeam/GuessForKid_V2/Source/Kidquiz/assets/image/INSTRUMENT"));
//		getFile("xxx");
		String value = "[\"https://blackloud-cvr-storage-cn.oss-cn-hangzhou.aliyuncs.com/600017962_20150817120634-1.avi?OSSAccessKeyId=C2KDFqa921KUr5qR&Expires=1439784518&Signature=kUeUswDzKC%2FqKSLMc6%2B%2Bae4pLWE%3D\"]";
		System.out.println(value.replaceAll("\\[\"|\"\\]", ""));
		String s = "https://blackloud-cvr-storage-cn.oss-cn-hangzhou.aliyuncs.com/600017962_20150817120634-1.avi?OSSAccessKeyId=C2KDFqa921KUr5qR&Expires=1439784518&Signature=kUeUswDzKC%2FqKSLMc6%2B%2Bae4pLWE%3D";
		
		int x = s.indexOf(".avi");
		s = s.substring(0, x);
//		StringBuilder s1 =  new StringBuilder(0, x);
		System.out.println(s.substring(s.lastIndexOf("_") + 1 , s.lastIndexOf("-")));
		String s2 = "20150817120634";
		System.out.println(s2.length());
		
	}

	static void listDirContents(Path path) {
		try {
			DirectoryStream<Path> directoryStream = Files
					.newDirectoryStream(path);
			StringBuilder stringBuilder = new StringBuilder();
			int i = 503;
			for (Path file : directoryStream) {
				stringBuilder
						.append("insert into question (id,image,answer,content,subj_id) values("
								+ i + ",'" + file.getFileName() + "','" + getFile(file.getFileName().toString())  +
								"','" + getFile(file.getFileName().toString()) + "',12); \n");
				i++;
				///System.out.println(file.getFileName());
			}
			System.out.println(stringBuilder.toString());
		} catch (IOException | DirectoryIteratorException e) {
			// IOException can never be thrown by the iteration.
			// In this snippet, it can only be thrown by newDirectoryStream.
			System.err.println(e);
		}
	}

	static String getFile(String Flagfile) {
		String ret = "";
		for (int i = 0; i < Flagfile.length(); i++) {
			Character c = Flagfile.charAt(i);
			if (c == '.')
				break;
			ret += c.toString();
		}
		return ret.toUpperCase();
	}
}
