/*
- * jSite - AbortedException.java - Copyright © 2010–2011 David Roden
+ * jSite - AbortedException.java - Copyright © 2010–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - FileOption.java - Copyright © 2006–2011 David Roden
+ * jSite - FileOption.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
/*
- * jSite - Freenet7Interface.java - Copyright © 2006–2011 David Roden
+ * jSite - Freenet7Interface.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - InsertListener.java - Copyright © 2006–2011 David Roden
+ * jSite - InsertListener.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - KeyDialog.java - Copyright © 2010–2011 David Roden
+ * jSite - KeyDialog.java - Copyright © 2010–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - Node.java - Copyright © 2006–2011 David Roden
+ * jSite - Node.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - Project.java - Copyright © 2006–2011 David Roden
+ * jSite - Project.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
/*
- * jSite - ProjectInserter.java - Copyright © 2006–2011 David Roden
+ * jSite - ProjectInserter.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - UpdateChecker.java - Copyright © 2008–2011 David Roden
+ * jSite - UpdateChecker.java - Copyright © 2008–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - UpdateListener.java - Copyright © 2008–2011 David Roden
+ * jSite - UpdateListener.java - Copyright © 2008–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - FileScanner.java - Copyright © 2006–2011 David Roden
+ * jSite - FileScanner.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - FileScannerListener.java - Copyright © 2006–2011 David Roden
+ * jSite - FileScannerListener.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - NodeManagerListener.java - Copyright © 2006–2011 David Roden
+ * jSite - NodeManagerListener.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - NodeManagerPage.java - Copyright © 2006–2011 David Roden
+ * jSite - NodeManagerPage.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - PreferencesPage.java - Copyright © 2009–2011 David Roden
+ * jSite - PreferencesPage.java - Copyright © 2009–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - ProjectFilesPage.java - Copyright © 2006–2011 David Roden
+ * jSite - ProjectFilesPage.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - ProjectInsertPage.java - Copyright © 2006–2011 David Roden
+ * jSite - ProjectInsertPage.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - ProjectPage.java - Copyright © 2006–2011 David Roden
+ * jSite - ProjectPage.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - I18n.java - Copyright © 2006–2011 David Roden
+ * jSite - I18n.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - I18nContainer.java - Copyright © 2007–2011 David Roden
+ * jSite - I18nContainer.java - Copyright © 2007–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
#
-# jSite - jSite.properties - Copyright © 2006–2011 David Roden
+# jSite - jSite.properties - Copyright © 2006–2012 David Roden
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#
-# jSite - jSite_de.properties - Copyright © 2006–2011 David Roden
+# jSite - jSite_de.properties - Copyright © 2006–2012 David Roden
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#
-# jSite - jSite_fr.properties - Copyright © 2006–2011 David Roden
+# jSite - jSite_fr.properties - Copyright © 2006–2012 David Roden
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
/*
- * jSite - CLI.java - Copyright © 2006–2011 David Roden
+ * jSite - CLI.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - Configuration.java - Copyright © 2006–2011 David Roden
+ * jSite - Configuration.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - ConfigurationLocator.java - Copyright © 2011 David Roden
+ * jSite - ConfigurationLocator.java - Copyright © 2011–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - Main.java - Copyright © 2006–2011 David Roden
+ * jSite - Main.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite - Version.java - Copyright © 2006–2011 David Roden
+ * jSite - Version.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - Client.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite-remote - ClientGet.java -
- * Copyright © 2008 David Roden
+ * jSite - ClientGet.java - Copyright © 2008–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - ClientHello.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - ClientPut.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - ClientPutComplexDir.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - ClientPutDir.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - Command.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - Connection.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - ConnectionListener.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - DirectFileEntry.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - DiskFileEntry.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - FileEntry.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - GenerateSSK.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - Message.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - Node.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - Persistence.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - PriorityClass.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - RedirectFileEntry.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * jSite-remote - ReturnType.java -
- * Copyright © 2008 David Roden
+ * jSite - ReturnType.java - Copyright © 2008–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - Verbosity.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
+ * jSite - IconLoader.java - Copyright © 2006–2012 David Roden
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
/*
- * todesbaum-lib - Copyright (C) 2006 David Roden
+ * jSite - Closer.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - LineInputStream.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
+ * jSite - StreamCopier.java - Copyright © 2006–2012 David Roden
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
--- /dev/null
+/*
+ * jSite - TeeOutputStream.java - Copyright © 2010 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package de.todesbaum.util.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * {@link OutputStream} that sends all data it receives to multiple other output
+ * streams. If an error occurs during a {@link #write(int)} to one of the
+ * underlying output streams no guarantees are made about how much data is sent
+ * to each stream, i.e. there is no good way to recover from such an error.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class TeeOutputStream extends OutputStream {
+
+ /** The output streams. */
+ private final OutputStream[] outputStreams;
+
+ /**
+ * Creates a new tee output stream that sends all to all given output
+ * streams.
+ *
+ * @param outputStreams
+ * The output streams to send all data to
+ */
+ public TeeOutputStream(OutputStream... outputStreams) {
+ this.outputStreams = outputStreams;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * An effort is made to close all output streams. If multiple exceptions
+ * occur, only the first exception is thrown after all output streams have
+ * been tried to close.
+ */
+ @Override
+ public void close() throws IOException {
+ IOException occuredException = null;
+ for (OutputStream outputStream : outputStreams) {
+ try {
+ outputStream.flush();
+ } catch (IOException ioe1) {
+ if (occuredException == null) {
+ occuredException = ioe1;
+ }
+ }
+ }
+ if (occuredException != null) {
+ throw occuredException;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * An effort is made to flush all output streams. If multiple exceptions
+ * occur, only the first exception is thrown after all output streams have
+ * been tried to flush.
+ */
+ @Override
+ public void flush() throws IOException {
+ IOException occuredException = null;
+ for (OutputStream outputStream : outputStreams) {
+ try {
+ outputStream.flush();
+ } catch (IOException ioe1) {
+ if (occuredException == null) {
+ occuredException = ioe1;
+ }
+ }
+ }
+ if (occuredException != null) {
+ throw occuredException;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void write(byte[] buffer) throws IOException {
+ for (OutputStream outputStream : outputStreams) {
+ outputStream.write(buffer);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void write(byte[] buffer, int offset, int length) throws IOException {
+ for (OutputStream outputStream : outputStreams) {
+ outputStream.write(buffer, offset, length);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void write(int data) throws IOException {
+ for (OutputStream outputStream : outputStreams) {
+ outputStream.write(data);
+ }
+ }
+
+}
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - TempFileInputStream.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - SortedListModel.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - TLabel.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - TWizard.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - TWizardPage.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * todesbaum-lib -
- * Copyright (C) 2006 David Roden
+ * jSite - WizardListener.java - Copyright © 2006–2012 David Roden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
+ * jSite - SimpleXML.java - Copyright © 2006–2012 David Roden
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
/*
+ * jSite - XML.java - Copyright © 2006–2012 David Roden
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later