⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileutil.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   FileUtil.java

package org.pf.file;

import java.io.*;
import org.pf.text.StringUtil;

// Referenced classes of package org.pf.file:
//			LineProcessor

public class FileUtil
{

	public static final String LINE_SEPARATOR = System.getProperty("line.separator");
	protected static final int DEFAULT_BUFFER_SIZE = 1024;
	private static FileUtil current = new FileUtil();

	private FileUtil()
	{
	}

	public static FileUtil current()
	{
		return current;
	}

	public void copyStream(InputStream inStream, OutputStream outStream)
		throws IOException
	{
		copyStream(inStream, outStream, 1024);
	}

	public void copyStream(InputStream inStream, OutputStream outStream, int bufSize)
		throws IOException
	{
		byte buffer[] = new byte[bufSize];
		for (int count = inStream.read(buffer); count > -1; count = inStream.read(buffer))
			outStream.write(buffer, 0, count);

		close(inStream);
		close(outStream);
		break MISSING_BLOCK_LABEL_71;
		Exception exception;
		exception;
		close(inStream);
		close(outStream);
		throw exception;
	}

	public String readTextFrom(InputStream inStream)
		throws IOException
	{
		StringWriter writer = new StringWriter(1024);
		copyText(inStream, writer);
		return writer.toString();
	}

	public String readTextFrom(String filename)
		throws IOException
	{
		FileInputStream inStream = new FileInputStream(filename);
		return readTextFrom(((InputStream) (inStream)));
	}

	public String readTextFrom(File file)
		throws IOException
	{
		FileInputStream inStream = new FileInputStream(file);
		return readTextFrom(((InputStream) (inStream)));
	}

	public void copyText(Reader reader, final StringWriter writer)
		throws IOException
	{
		BufferedReader bufReader = new BufferedReader(reader);
		LineProcessor processor = new LineProcessor() {

			final StringWriter val$writer;
			final FileUtil this$0;

			public boolean processLine(String line, int lineNo)
			{
				if (lineNo > 1)
					writer.write(FileUtil.LINE_SEPARATOR);
				writer.write(line);
				return true;
			}

			
			{
				this$0 = FileUtil.this;
				writer = stringwriter;
				super();
			}
		};
		processTextLines(bufReader, processor);
		bufReader.close();
		break MISSING_BLOCK_LABEL_43;
		Exception exception;
		exception;
		bufReader.close();
		throw exception;
	}

	public void processTextLines(String filename, LineProcessor processor)
		throws IOException
	{
		if (filename == null)
		{
			throw new IllegalArgumentException("filename must not be null");
		} else
		{
			FileInputStream inStream = new FileInputStream(filename);
			processTextLines(((InputStream) (inStream)), processor);
			return;
		}
	}

	public void processTextLines(InputStream inStream, LineProcessor processor)
		throws IOException
	{
		if (inStream == null)
		{
			throw new IllegalArgumentException("inStream must not be null");
		} else
		{
			InputStreamReader reader = new InputStreamReader(inStream);
			processTextLines(((Reader) (reader)), processor);
			return;
		}
	}

	public void processTextLines(Reader reader, LineProcessor processor)
		throws IOException
	{
		int counter = 0;
		boolean continue_reading = true;
		if (reader == null)
			throw new IllegalArgumentException("reader must not be null");
		if (processor == null)
			throw new IllegalArgumentException("processor must not be null");
		BufferedReader bufReader = new BufferedReader(reader);
		do
		{
			if (!continue_reading || !bufReader.ready())
				break;
			String line = bufReader.readLine();
			if (line == null)
				break;
			counter++;
			continue_reading = processor.processLine(line, counter);
		} while (true);
	}

	public boolean close(InputStream stream)
	{
		if (stream == null)
			return false;
		stream.close();
		return true;
		IOException e;
		e;
		return false;
	}

	public boolean close(OutputStream stream)
	{
		if (stream == null)
			return false;
		stream.close();
		return true;
		IOException e;
		e;
		return false;
	}

	public String standardize(String filename)
	{
		if (filename == null)
			return null;
		else
			return standardizeFilename(filename);
	}

	public String javaFilename(String filename)
	{
		if (filename == null)
			return null;
		else
			return filename.replace('\\', '/');
	}

	protected void copyText(InputStream inStream, StringWriter writer)
		throws IOException
	{
		copyText(((Reader) (new InputStreamReader(inStream))), writer);
	}

	protected String standardizeFilename(String filename)
	{
		filename = javaFilename(filename);
		boolean startedFromRoot = filename.startsWith("/");
		String nameElements[] = str().parts(filename, "/");
		if (nameElements.length > 0)
		{
			boolean hasDriveLetter = nameElements[0].endsWith(":");
			if (hasDriveLetter)
				nameElements[0] = nameElements[0].toUpperCase();
			else
			if (startedFromRoot)
				nameElements = str().append(new String[] {
					""
				}, nameElements);
			boolean isAbsolute = hasDriveLetter || startedFromRoot;
			for (int i = 0; i < nameElements.length; i++)
			{
				if (".".equals(nameElements[i]))
				{
					nameElements[i] = null;
					continue;
				}
				if (!"..".equals(nameElements[i]))
					continue;
				int index = indexOfPreceedingNotNullElement(nameElements, i - 1);
				if (index >= 0 && (index > 0 || !isAbsolute))
				{
					nameElements[i] = null;
					nameElements[index] = null;
				}
			}

			nameElements = str().removeNull(nameElements);
			return str().asString(nameElements, "/");
		} else
		{
			return "";
		}
	}

	protected int indexOfPreceedingNotNullElement(String elements[], int start)
	{
		for (int i = start; i >= 0; i--)
			if (elements[i] != null)
				if ("..".equals(elements[i]))
					return -1;
				else
					return i;

		return -1;
	}

	protected StringUtil str()
	{
		return StringUtil.current();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -