Java FileOutputStream Create getOutputStream(String filename, Map map)

Here you can find the source of getOutputStream(String filename, Map map)

Description

Returns the OutputStream contained in the map , if present, or creates a new OutputStream attached to the specified file.

License

Open Source License

Parameter

Parameter Description
filename the name of the file to open, or one of the keys in map .
map a map of names to existing OutputStreams

Exception

Parameter Description
FileNotFoundException if the requested file does not exist.

Return

either the OutputStream in the map, or a new OutputStream .

Declaration

public static OutputStream getOutputStream(String filename, Map<String, OutputStream> map)
        throws FileNotFoundException 

Method Source Code

//package com.java2s;
/**/*from   w  w  w .ja  v  a  2 s. c  o  m*/
 * Copyright (c) Zachary Kurmas 2011
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import java.io.*;

import java.util.Map;

public class Main {
    /**
     * Returns the {@code OutputStream} contained in the {@code map}, if present,
     * or creates a new {@code OutputStream }attached to the specified file.  {@link #DEFAULT_OUTPUT_STREAM_MAP} maps
     * common names for the standard output and standard error to {@code System.out} and {@code System.err} respectively.
     *
     * @param filename the name of the file to open, or one of the keys in {@code map}.
     * @param map      a map of names to existing {@code OutputStreams}
     * @return either the {@code OutputStream} in the map, or a new {@code OutputStream}.
     * @throws FileNotFoundException if the requested file does not exist.
     */
    public static OutputStream getOutputStream(String filename, Map<String, OutputStream> map)
            throws FileNotFoundException {
        if (map != null && map.containsKey(filename)) {
            return map.get(filename);
        } else {
            return new FileOutputStream(filename);
        }
    }
}

Related

  1. getOutputStream(final File file)
  2. getOutputStream(final Object obj, final boolean append)
  3. getOutputStream(String file)
  4. getOutputStream(String filename)
  5. getOutputStream(String fileName)
  6. getOutputStream(String filename, String dir)
  7. getOutputStream(String fname, String enc, boolean append)
  8. getOutputStream(String path)
  9. getOutputStream(String path)