Package: ResourceFileNetBeansPlatformWritableFolder
ResourceFileNetBeansPlatformWritableFolder
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ResourceFileNetBeansPlatformWritableFolder(ResourceFileNetBeansPlatform) |
|
|
|
|
|
||||||||||||||||||||
openStream(String) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
write(String, Marshallable) |
|
|
|
|
|
||||||||||||||||||||
write(String, String) |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone git@bitbucket.org:tidalwave/northernwind-rca-src.git
7: * %%
8: * Copyright (C) 2013 - 2021 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.filesystem.impl;
28:
29: import javax.annotation.Nonnull;
30: import java.io.IOException;
31: import java.io.OutputStream;
32: import java.io.OutputStreamWriter;
33: import java.io.Writer;
34: import java.nio.charset.StandardCharsets;
35: import org.openide.filesystems.FileObject;
36: import it.tidalwave.dci.annotation.DciRole;
37: import it.tidalwave.role.io.Marshallable;
38: import it.tidalwave.northernwind.model.admin.role.WritableFolder;
39: import lombok.RequiredArgsConstructor;
40: import lombok.extern.slf4j.Slf4j;
41:
42: /***********************************************************************************************************************
43: *
44: * @stereotype role
45: *
46: * @author Fabrizio Giudici
47: *
48: **********************************************************************************************************************/
49:•@DciRole(datumType = ResourceFileNetBeansPlatform.class) @RequiredArgsConstructor @Slf4j
50: public class ResourceFileNetBeansPlatformWritableFolder implements WritableFolder
51: {
52: @Nonnull
53: private final ResourceFileNetBeansPlatform file;
54:
55: @Override
56: public synchronized void write (@Nonnull final String fileName, @Nonnull final String text)
57: throws IOException
58: {
59: try (final Writer w = new OutputStreamWriter(openStream(fileName), StandardCharsets.UTF_8))
60: {
61: w.write(text);
62: }
63: }
64:
65: @Override
66: public void write (@Nonnull final String fileName, @Nonnull final Marshallable marshallable)
67: throws IOException
68: {
69: try (final OutputStream os = openStream(fileName))
70: {
71: marshallable.marshal(os);
72: }
73: }
74:
75: @Nonnull
76: private OutputStream openStream (@Nonnull final String fileName)
77: throws IOException
78: {
79: FileObject fileObject = file.getDelegate().getFileObject(fileName);
80:
81:• if (fileObject == null)
82: {
83: fileObject = file.getDelegate().createData(fileName);
84: }
85:
86: log.debug("opening stream: {}", fileObject);
87: return fileObject.getOutputStream();
88: }
89: }