1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
   | 	/**
	 * This fonction permits to search the Information in the File
	 * 
	 * @param Info
	 * @param file
	 * @return
	 */
	public boolean SearchInfo(Information Info, File file, String LogPath) {
		boolean infoFound = false;
		String FileContent;
		try {
			InputStream in = new BufferedInputStream(new FileInputStream(file));
			byte[] bytes = new byte[in.available()];
			in.read(bytes);
			// Attention pe faut-il utiliser le constructeur (byte[] bytes, //
			FileContent = new String(bytes);
			// TQ il reste le mot de debut et qu'on a pas trouve if
			int beginContent, EndOfContent, newBeforeString;
			beginContent = FileContent.indexOf(Info.beforeString);
			if (beginContent != -1) {
				EndOfContent = FileContent.indexOf(Info.afterString,
						beginContent);
				if (EndOfContent != -1) {
					do {
						newBeforeString = FileContent.indexOf(
								Info.beforeString, beginContent + 1);
						if (newBeforeString != -1
								&& newBeforeString < EndOfContent) {
							beginContent = newBeforeString;
						} else {
							Info.content = FileContent.substring(beginContent,
									EndOfContent);
							infoFound = true;
						}
					} while (newBeforeString != -1
							&& newBeforeString < EndOfContent);
				} else {
					LogHelper.addText(IHMHelper.logDate()
							+ " : Error Information " + Info.label
							+ " can not be found ", LogPath);
					LogHelper.addText(IHMHelper.logDate()
							+ " : Error Reason : " + Info.afterString
							+ " can not be found ", LogPath);
				}
			} else {
				LogHelper.addText(IHMHelper.logDate() + " : Information "
						+ Info.label + " can not be found ", LogPath);
				LogHelper.addText(IHMHelper.logDate() + " : Reason : "
						+ Info.beforeString + " can not be found ", LogPath);
			}
			in.close();
		}
		catch (IOException e) {
			LogHelper.addText(IHMHelper.logDate() + " : ERROR "
					+ e.getLocalizedMessage(), LogPath);
		}
		// System.out.println(Info.content);
		return infoFound;
	} | 
Partager