// Path: src/main/java/de/todesbaum/util/io/LineInputStream.java
// public class LineInputStream extends FilterInputStream {
// 
// 	private boolean skipLinefeed = false;
// 	private StringBuffer lineBuffer = new StringBuffer();
// 
// 	/**
// 	 * @param in
// 	 */
// 	public LineInputStream(InputStream in) {
// 		super(in);
// 	}
// 
// 	public synchronized String readLine() throws IOException {
// 		lineBuffer.setLength(0);
// 		int c = 0;
// 		while (c != -1) {
// 			c = read();
// 			if ((c == -1) && lineBuffer.length() == 0)
// 				return null;
// 			if (skipLinefeed && (c == '\n')) {
// 				skipLinefeed = false;
// 				continue;
// 			}
// 			skipLinefeed = (c == '\r');
// 			if ((c == '\r') || (c == '\n')) {
// 				c = -1;
// 			} else {
// 				lineBuffer.append((char) c);
// 			}
// 		}
// 		return lineBuffer.toString();
// 	}
// 
// }
// 
// Path: src/main/java/de/todesbaum/util/io/TempFileInputStream.java
// public class TempFileInputStream extends FileInputStream {
// 
// 	private File tempFile;
// 
// 	/**
// 	 * @param name
// 	 * @throws FileNotFoundException
// 	 */
// 	public TempFileInputStream(String name) throws FileNotFoundException {
// 		this(new File(name));
// 	}
// 
// 	/**
// 	 * @param file
// 	 * @throws FileNotFoundException
// 	 */
// 	public TempFileInputStream(File file) throws FileNotFoundException {
// 		super(file);
// 		tempFile = file;
// 	}
// 
// 	@Override
// 	public void close() throws IOException {
// 		super.close();
// 		tempFile.delete();
// 	}
// 
// }


import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.io.StreamCopier;
import net.pterodactylus.util.io.StreamCopier.ProgressListener;
import de.todesbaum.util.io.LineInputStream;
import de.todesbaum.util.io.TempFileInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.Socket;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
		 * Main loop of the reader. Lines are read and converted into
		 * {@link Message} objects.
		 */
		@SuppressWarnings("synthetic-access")
		public void run() {
			LineInputStream nodeReader = null;
			try {
				nodeReader = new LineInputStream(nodeInputStream);
				String line = "";
				Message message = null;
				while (line != null) {
					line = nodeReader.readLine();
					// System.err.println("> " + line);
					if (line == null) {
						break;
					}
					if (message == null) {
						message = new Message(line);
						continue;
					}
					if ("Data".equals(line)) {
						/* need to read message from stream now */
						File tempFile = null;
						try {
							tempFile = File.createTempFile("fcpv2", "data", (tempDirectory != null) ? new File(tempDirectory) : null);
							tempFile.deleteOnExit();
							FileOutputStream tempFileOutputStream = new FileOutputStream(tempFile);
							long dataLength = Long.parseLong(message.get("DataLength"));
							StreamCopier.copy(nodeInputStream, tempFileOutputStream, dataLength);
							tempFileOutputStream.close();
// Path: src/main/java/de/todesbaum/util/io/LineInputStream.java
// public class LineInputStream extends FilterInputStream {
// 
// 	private boolean skipLinefeed = false;
// 	private StringBuffer lineBuffer = new StringBuffer();
// 
// 	/**
// 	 * @param in
// 	 */
// 	public LineInputStream(InputStream in) {
// 		super(in);
// 	}
// 
// 	public synchronized String readLine() throws IOException {
// 		lineBuffer.setLength(0);
// 		int c = 0;
// 		while (c != -1) {
// 			c = read();
// 			if ((c == -1) && lineBuffer.length() == 0)
// 				return null;
// 			if (skipLinefeed && (c == '\n')) {
// 				skipLinefeed = false;
// 				continue;
// 			}
// 			skipLinefeed = (c == '\r');
// 			if ((c == '\r') || (c == '\n')) {
// 				c = -1;
// 			} else {
// 				lineBuffer.append((char) c);
// 			}
// 		}
// 		return lineBuffer.toString();
// 	}
// 
// }
// 
// Path: src/main/java/de/todesbaum/util/io/TempFileInputStream.java
// public class TempFileInputStream extends FileInputStream {
// 
// 	private File tempFile;
// 
// 	/**
// 	 * @param name
// 	 * @throws FileNotFoundException
// 	 */
// 	public TempFileInputStream(String name) throws FileNotFoundException {
// 		this(new File(name));
// 	}
// 
// 	/**
// 	 * @param file
// 	 * @throws FileNotFoundException
// 	 */
// 	public TempFileInputStream(File file) throws FileNotFoundException {
// 		super(file);
// 		tempFile = file;
// 	}
// 
// 	@Override
// 	public void close() throws IOException {
// 		super.close();
// 		tempFile.delete();
// 	}
// 
// }


// Path: src/main/java/de/todesbaum/util/freenet/fcp2/Connection.java
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.io.StreamCopier;
import net.pterodactylus.util.io.StreamCopier.ProgressListener;
import de.todesbaum.util.io.LineInputStream;
import de.todesbaum.util.io.TempFileInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.Socket;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

		 * Main loop of the reader. Lines are read and converted into
		 * {@link Message} objects.
		 */
		@SuppressWarnings("synthetic-access")
		public void run() {
			LineInputStream nodeReader = null;
			try {
				nodeReader = new LineInputStream(nodeInputStream);
				String line = "";
				Message message = null;
				while (line != null) {
					line = nodeReader.readLine();
					// System.err.println("> " + line);
					if (line == null) {
						break;
					}
					if (message == null) {
						message = new Message(line);
						continue;
					}
					if ("Data".equals(line)) {
						/* need to read message from stream now */
						File tempFile = null;
						try {
							tempFile = File.createTempFile("fcpv2", "data", (tempDirectory != null) ? new File(tempDirectory) : null);
							tempFile.deleteOnExit();
							FileOutputStream tempFileOutputStream = new FileOutputStream(tempFile);
							long dataLength = Long.parseLong(message.get("DataLength"));
							StreamCopier.copy(nodeInputStream, tempFileOutputStream, dataLength);
							tempFileOutputStream.close();
							message.setPayloadInputStream(new TempFileInputStream(tempFile));