[Japi-cvs] SF.net SVN: japi: [512] libs/io/trunk/src
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-07-07 09:47:51
|
Revision: 512 http://svn.sourceforge.net/japi/?rev=512&view=rev Author: christianhujer Date: 2007-07-07 02:47:49 -0700 (Sat, 07 Jul 2007) Log Message: ----------- Moved Copier to IO lib. Added Paths: ----------- libs/io/trunk/libs-io.iml libs/io/trunk/src/net/ libs/io/trunk/src/net/sf/ libs/io/trunk/src/net/sf/jaoi/ libs/io/trunk/src/net/sf/jaoi/io/ libs/io/trunk/src/net/sf/japi/ libs/io/trunk/src/net/sf/japi/io/ libs/io/trunk/src/net/sf/japi/io/Copier.java Removed Paths: ------------- historic/trunk/src/app/net/sf/japi/io/Copier.java Deleted: historic/trunk/src/app/net/sf/japi/io/Copier.java =================================================================== --- historic/trunk/src/app/net/sf/japi/io/Copier.java 2007-07-07 09:35:46 UTC (rev 511) +++ historic/trunk/src/app/net/sf/japi/io/Copier.java 2007-07-07 09:47:49 UTC (rev 512) @@ -1,122 +0,0 @@ -/* - * JAPI - (Yet another (hopefully) useful) Java API - * - * Copyright (C) 2006 Christian Hujer - * - * 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 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -package net.sf.japi.io; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; - -/** A Runnable that copies from an InputStream to an OutputStream. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public class Copier implements Runnable { - - /** Default buffer size when copying. */ - public static final int DEFAULT_BUF_SIZE = 8192; - - /** Default automatic flush. */ - public static final boolean DEFAULT_AUTO_FLUSH = true; - - /** Default automatic close. */ - public static final boolean DEFAULT_AUTO_CLOSE = true; - - /** The InputStream to read from. */ - private final InputStream in; - - /** The OutputStream to write to. */ - private final OutputStream out; - - /** The buffer size to use. */ - private final int bufSize; - - /** Whether to flush automatically. */ - private final boolean autoFlush; - - /** Whether to close streams automatically after copying. */ - private final boolean autoClose; - - /** Create a Copier with default buffer size and autoFlush. - * @param in the InputStream to read from - * @param out the OutputStream to write to - */ - public Copier(final InputStream in, final OutputStream out) { - this(in, out, DEFAULT_BUF_SIZE, DEFAULT_AUTO_FLUSH, DEFAULT_AUTO_CLOSE); - } - - /** Create a Copier with specified buffer size and automatic flush behaviour. - * @param in the InputStream to read from - * @param out the OutputStream to write to - * @param bufSize buffer size to use while copying - */ - public Copier(final InputStream in, final OutputStream out, final int bufSize) { - this(in, out, bufSize, DEFAULT_AUTO_FLUSH, DEFAULT_AUTO_CLOSE); - } - - /** Create a Copier with specified buffer size and specified flush behaviour. - * @param in the InputStream to read from - * @param out the OutputStream to write to - * @param bufSize buffer size to use while copying - * @param autoFlush whether to flush automatically (true for automatic flush, false for flush on close) - * @param autoClose whether to close the streams automatically (true for automatic close, false for no close) - */ - public Copier(final InputStream in, final OutputStream out, final int bufSize, final boolean autoFlush, final boolean autoClose) { - this.in = in; - this.out = out; - this.bufSize = bufSize; - this.autoFlush = autoFlush; - this.autoClose = autoClose; - } - - /** Start the copier in a new thread. - * @return the newly created thread - */ - public Thread start() { - final Thread thread = new Thread(this); - thread.start(); - return thread; - } - - /** {@inheritDoc} */ - public void run() { - final byte[] buf = new byte[bufSize]; - try { - for (int bytesRead; (bytesRead = in.read(buf)) != -1;) { - out.write(buf, 0, bytesRead); - if (autoFlush) { - out.flush(); - } - } - } catch (final IOException e) { - System.err.println(e); - } finally { - //noinspection CatchGenericClass,OverlyBroadCatchBlock - try { out.flush(); } catch (final Exception ignore) { /* ignore */ } - if (autoClose) { - //noinspection CatchGenericClass,OverlyBroadCatchBlock - try { out.close(); } catch (final Exception ignore) { /* ignore */ } - //noinspection CatchGenericClass,OverlyBroadCatchBlock - try { in.close(); } catch (final Exception ignore) { /* ignore */ } - } - } - } - -} // class Copier Added: libs/io/trunk/libs-io.iml =================================================================== --- libs/io/trunk/libs-io.iml (rev 0) +++ libs/io/trunk/libs-io.iml 2007-07-07 09:47:49 UTC (rev 512) @@ -0,0 +1,187 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module relativePaths="true" type="JAVA_MODULE" version="4"> + <component name="ModuleRootManager" /> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntryProperties /> + </component> + <component name="copyright"> + <Base> + <setting name="state" value="1" /> + </Base> + <LanguageOptions name="$TEMPLATE$"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="4" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="CSS"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="HTML"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="JAVA"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="JSP"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="JavaScript"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="Properties"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + <LanguageOptions name="XML"> + <option name="templateOptions"> + <value> + <option name="block" value="true" /> + <option name="separateBefore" value="false" /> + <option name="separateAfter" value="false" /> + <option name="prefixLines" value="true" /> + <option name="lenBefore" value="80" /> + <option name="lenAfter" value="80" /> + <option name="box" value="false" /> + <option name="filler" value=" " /> + </value> + </option> + <option name="notice" value="Copyright (c) &#36;today.year, Your Corporation. All Rights Reserved." /> + <option name="keyword" value="Copyright" /> + <option name="fileTypeOverride" value="2" /> + <option name="relativeBefore" value="true" /> + <option name="addBlankAfter" value="true" /> + <option name="fileLocation" value="1" /> + <option name="useAlternate" value="false" /> + </LanguageOptions> + </component> +</module> + Property changes on: libs/io/trunk/libs-io.iml ___________________________________________________________________ Name: svn:mime-type + text/xml Name: svn:eol-style + LF Added: libs/io/trunk/src/net/sf/japi/io/Copier.java =================================================================== --- libs/io/trunk/src/net/sf/japi/io/Copier.java (rev 0) +++ libs/io/trunk/src/net/sf/japi/io/Copier.java 2007-07-07 09:47:49 UTC (rev 512) @@ -0,0 +1,122 @@ +/* + * JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2006 Christian Hujer + * + * 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 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package net.sf.japi.io; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +/** A Runnable that copies from an InputStream to an OutputStream. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class Copier implements Runnable { + + /** Default buffer size when copying. */ + public static final int DEFAULT_BUF_SIZE = 8192; + + /** Default automatic flush. */ + public static final boolean DEFAULT_AUTO_FLUSH = true; + + /** Default automatic close. */ + public static final boolean DEFAULT_AUTO_CLOSE = true; + + /** The InputStream to read from. */ + private final InputStream in; + + /** The OutputStream to write to. */ + private final OutputStream out; + + /** The buffer size to use. */ + private final int bufSize; + + /** Whether to flush automatically. */ + private final boolean autoFlush; + + /** Whether to close streams automatically after copying. */ + private final boolean autoClose; + + /** Create a Copier with default buffer size and autoFlush. + * @param in the InputStream to read from + * @param out the OutputStream to write to + */ + public Copier(final InputStream in, final OutputStream out) { + this(in, out, DEFAULT_BUF_SIZE, DEFAULT_AUTO_FLUSH, DEFAULT_AUTO_CLOSE); + } + + /** Create a Copier with specified buffer size and automatic flush behaviour. + * @param in the InputStream to read from + * @param out the OutputStream to write to + * @param bufSize buffer size to use while copying + */ + public Copier(final InputStream in, final OutputStream out, final int bufSize) { + this(in, out, bufSize, DEFAULT_AUTO_FLUSH, DEFAULT_AUTO_CLOSE); + } + + /** Create a Copier with specified buffer size and specified flush behaviour. + * @param in the InputStream to read from + * @param out the OutputStream to write to + * @param bufSize buffer size to use while copying + * @param autoFlush whether to flush automatically (true for automatic flush, false for flush on close) + * @param autoClose whether to close the streams automatically (true for automatic close, false for no close) + */ + public Copier(final InputStream in, final OutputStream out, final int bufSize, final boolean autoFlush, final boolean autoClose) { + this.in = in; + this.out = out; + this.bufSize = bufSize; + this.autoFlush = autoFlush; + this.autoClose = autoClose; + } + + /** Start the copier in a new thread. + * @return the newly created thread + */ + public Thread start() { + final Thread thread = new Thread(this); + thread.start(); + return thread; + } + + /** {@inheritDoc} */ + public void run() { + final byte[] buf = new byte[bufSize]; + try { + for (int bytesRead; (bytesRead = in.read(buf)) != -1;) { + out.write(buf, 0, bytesRead); + if (autoFlush) { + out.flush(); + } + } + } catch (final IOException e) { + System.err.println(e); + } finally { + //noinspection CatchGenericClass,OverlyBroadCatchBlock + try { out.flush(); } catch (final Exception ignore) { /* ignore */ } + if (autoClose) { + //noinspection CatchGenericClass,OverlyBroadCatchBlock + try { out.close(); } catch (final Exception ignore) { /* ignore */ } + //noinspection CatchGenericClass,OverlyBroadCatchBlock + try { in.close(); } catch (final Exception ignore) { /* ignore */ } + } + } + } + +} // class Copier Property changes on: libs/io/trunk/src/net/sf/japi/io/Copier.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |