Package: PathTextWritable
PathTextWritable
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PathTextWritable(Path) |
|
|
|
|
|
||||||||||||||||||||
PathTextWritable(Path, Charset, OpenOption[]) |
|
|
|
|
|
||||||||||||||||||||
openWriter() |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.role.io.spi;
28:
29: import javax.annotation.Nonnull;
30: import java.io.IOException;
31: import java.io.Writer;
32: import java.nio.charset.Charset;
33: import java.nio.charset.StandardCharsets;
34: import java.nio.file.Files;
35: import java.nio.file.OpenOption;
36: import java.nio.file.Path;
37: import it.tidalwave.role.io.TextWritable;
38:
39: /***********************************************************************************************************************
40: *
41: * An implementation of {@link TextWritable} which delegates to a {@link Path}.
42: *
43: * @author Fabrizio Giudici
44: * @since 3.2-ALPHA-12
45: * @it.tidalwave.javadoc.stable
46: *
47: **********************************************************************************************************************/
48: public class PathTextWritable implements TextWritable
49: {
50: @Nonnull
51: private final Path path;
52:
53: @Nonnull
54: private final Charset charset;
55:
56: @Nonnull
57: private final OpenOption[] openOptions;
58:
59: /*******************************************************************************************************************
60: *
61: * Creates an instance with the given path and options.
62: *
63: * @param path the path to open
64: *
65: ******************************************************************************************************************/
66: public PathTextWritable (@Nonnull final Path path)
67: {
68: this(path, StandardCharsets.UTF_8);
69: }
70:
71: /*******************************************************************************************************************
72: *
73: * Creates an instance with the given path and options.
74: *
75: * @param path the path to open
76: * @param charset the character set
77: * @param openOptions open options
78: *
79: ******************************************************************************************************************/
80: public PathTextWritable (@Nonnull final Path path,
81: @Nonnull final Charset charset,
82: @Nonnull final OpenOption... openOptions)
83: {
84: this.path = path;
85: this.charset = charset;
86: this.openOptions = openOptions;
87: }
88:
89: /*******************************************************************************************************************
90: *
91: * {@inheritDoc}
92: *
93: ******************************************************************************************************************/
94: @Override @Nonnull
95: public Writer openWriter()
96: throws IOException
97: {
98: return Files.newBufferedWriter(path, charset, openOptions);
99: }
100: }