You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2017/05/03 17:37:34 UTC
tomee git commit: ensure we dont close System.out,
small style refactoring on PropertiesAdapter
Repository: tomee
Updated Branches:
refs/heads/master 703e97708 -> d8d7bc6fd
ensure we dont close System.out, small style refactoring on PropertiesAdapter
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/d8d7bc6f
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/d8d7bc6f
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/d8d7bc6f
Branch: refs/heads/master
Commit: d8d7bc6fd9e4d490dc98a070e5d5e58f169090ea
Parents: 703e977
Author: rmannibucau <rm...@apache.org>
Authored: Wed May 3 19:37:27 2017 +0200
Committer: rmannibucau <rm...@apache.org>
Committed: Wed May 3 19:37:27 2017 +0200
----------------------------------------------------------------------
.../openejb/util/JuliLogStreamFactory.java | 29 +++++++++++++++++++-
.../openejb/jee/oejb3/PropertiesAdapter.java | 28 +++++++++----------
2 files changed, 42 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/d8d7bc6f/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java b/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java
index a40850e..3dc2291 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java
@@ -24,6 +24,8 @@ import org.apache.openejb.log.SingleLineFormatter;
import org.apache.openejb.util.reflection.Reflections;
import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import java.io.FilterOutputStream;
+import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.util.logging.ConsoleHandler;
@@ -208,7 +210,32 @@ public class JuliLogStreamFactory implements LogStreamFactory {
@Override
protected synchronized void setOutputStream(final OutputStream out) throws SecurityException {
- super.setOutputStream(System.out);
+ super.setOutputStream(new FilterOutputStream(System.out) { // don't close System.out to not loose important things like exceptions
+ @Override
+ public void write(final int b) throws IOException {
+ System.out.write(b);
+ }
+
+ @Override
+ public void write(final byte[] b) throws IOException {
+ System.out.write(b);
+ }
+
+ @Override
+ public void write(final byte[] b, final int off, final int len) throws IOException {
+ System.out.write(b, off, len);
+ }
+
+ @Override
+ public void flush() throws IOException {
+ System.out.flush();
+ }
+
+ @Override
+ public void close() throws IOException {
+ flush();
+ }
+ });
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/d8d7bc6f/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java
----------------------------------------------------------------------
diff --git a/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java b/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java
index d18ab87..6c40b64 100644
--- a/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java
+++ b/container/openejb-jee/src/main/java/org/apache/openejb/jee/oejb3/PropertiesAdapter.java
@@ -5,14 +5,14 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.openejb.jee.oejb3;
@@ -40,7 +40,7 @@ public class PropertiesAdapter extends XmlAdapter<String, Properties> {
if (properties == null) return null;
final ByteArrayOutputStream out = new ByteArrayOutputStream();
- new Properties() { // sort entries as before java 9
+ new Properties() { // sort entries as before java 9, todo: decide if we want to sort it like that or if we just stop from being deterministic there
{
putAll(properties);
}
@@ -48,18 +48,18 @@ public class PropertiesAdapter extends XmlAdapter<String, Properties> {
@Override
public Set<Map.Entry<Object, Object>> entrySet() {
final Set<Map.Entry<Object, Object>> entrySet = super.entrySet();
- return new TreeSet<Map.Entry<Object, Object>>(new Comparator<Map.Entry<Object, Object>>() {
+ final Set<Map.Entry<Object, Object>> entries = new TreeSet<>(new Comparator<Map.Entry<Object, Object>>() {
@Override
public int compare(final Map.Entry<Object, Object> o1, final Map.Entry<Object, Object> o2) {
return String.valueOf(o1.getKey()).compareTo(String.valueOf(o2.getKey()));
}
- }) {{
- addAll(entrySet);
- }};
+ });
+ entries.addAll(entrySet);
+ return entries;
}
}.store(out, null);
- // First comment is added by properties.store()
+ // First comment is added by properties.store()
final String string = new String(out.toByteArray());
return string.replaceFirst("#.*?" + System.lineSeparator(), "");
}