|
@@ -1,133 +0,0 @@
|
|
|
-package com.uas.ps.product.util;
|
|
|
|
|
-
|
|
|
|
|
-import java.io.*;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @author sunyj
|
|
|
|
|
- * @since 2018/1/6 17:39
|
|
|
|
|
- */
|
|
|
|
|
-public class FileBuffer {
|
|
|
|
|
- private String filePath;
|
|
|
|
|
- private BufferedWriter writer;
|
|
|
|
|
- private BufferedReader reader;
|
|
|
|
|
-
|
|
|
|
|
- public FileBuffer(String folderPath, String fileName) {
|
|
|
|
|
- File file = new File(folderPath);
|
|
|
|
|
- if (!file.isDirectory()) {
|
|
|
|
|
- file.mkdirs();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.filePath = folderPath + File.separator + fileName;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public synchronized boolean append(String content) {
|
|
|
|
|
- if (this.writer == null) {
|
|
|
|
|
- try {
|
|
|
|
|
- File file = new File(this.filePath);
|
|
|
|
|
- if (!file.exists()) {
|
|
|
|
|
- file.createNewFile();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.writer = new BufferedWriter(new FileWriter(file, true));
|
|
|
|
|
- } catch (IOException var5) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- try {
|
|
|
|
|
- this.writer.write("\r\n");
|
|
|
|
|
- } catch (IOException var4) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- this.writer.write(content);
|
|
|
|
|
- this.writer.flush();
|
|
|
|
|
- return true;
|
|
|
|
|
- } catch (IOException var3) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public synchronized String readLine() {
|
|
|
|
|
- if (this.writer != null) {
|
|
|
|
|
- this.close();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (this.reader == null) {
|
|
|
|
|
- File file = new File(this.filePath);
|
|
|
|
|
- if (file.exists()) {
|
|
|
|
|
- try {
|
|
|
|
|
- InputStreamReader streamReader = new InputStreamReader(new FileInputStream(file));
|
|
|
|
|
- this.reader = new BufferedReader(streamReader);
|
|
|
|
|
- } catch (FileNotFoundException var3) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (this.reader != null) {
|
|
|
|
|
- try {
|
|
|
|
|
- return this.reader.readLine();
|
|
|
|
|
- } catch (IOException var4) {
|
|
|
|
|
- ;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public synchronized void close() {
|
|
|
|
|
- if (this.writer != null) {
|
|
|
|
|
- try {
|
|
|
|
|
- this.writer.close();
|
|
|
|
|
- } catch (IOException var5) {
|
|
|
|
|
- ;
|
|
|
|
|
- } finally {
|
|
|
|
|
- this.writer = null;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public synchronized void delete() {
|
|
|
|
|
- if (this.writer != null) {
|
|
|
|
|
- try {
|
|
|
|
|
- this.writer.close();
|
|
|
|
|
- } catch (IOException var14) {
|
|
|
|
|
- ;
|
|
|
|
|
- } finally {
|
|
|
|
|
- this.writer = null;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (this.reader != null) {
|
|
|
|
|
- try {
|
|
|
|
|
- this.reader.close();
|
|
|
|
|
- } catch (IOException var12) {
|
|
|
|
|
- ;
|
|
|
|
|
- } finally {
|
|
|
|
|
- this.reader = null;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- File file = new File(this.filePath);
|
|
|
|
|
- if (file.exists()) {
|
|
|
|
|
- file.delete();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public synchronized boolean isEmpty() {
|
|
|
|
|
- boolean empty = this.writer == null;
|
|
|
|
|
- if (!empty) {
|
|
|
|
|
- File file = new File(this.filePath);
|
|
|
|
|
- empty = !file.exists();
|
|
|
|
|
- if (!empty) {
|
|
|
|
|
- empty = file.length() == 0L;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return empty;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|