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
- getOutputStream(final File file)
- getOutputStream(final Object obj, final boolean append)
- getOutputStream(String file)
- getOutputStream(String filename)
- getOutputStream(String fileName)
- getOutputStream(String filename, String dir)
- getOutputStream(String fname, String enc, boolean append)
- getOutputStream(String path)
- getOutputStream(String path)