View Javadoc
1   package org.apache.maven.surefire.booter.stream;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.surefire.api.booter.ForkedProcessEventType;
23  import org.apache.maven.surefire.api.stream.AbstractStreamEncoder;
24  import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
25  
26  import javax.annotation.Nonnull;
27  import java.nio.charset.Charset;
28  import java.nio.charset.CharsetEncoder;
29  
30  import static org.apache.maven.surefire.api.booter.Constants.DEFAULT_STREAM_ENCODING;
31  import static org.apache.maven.surefire.api.booter.Constants.DEFAULT_STREAM_ENCODING_BYTES;
32  import static org.apache.maven.surefire.api.booter.Constants.MAGIC_NUMBER_FOR_EVENTS_BYTES;
33  
34  /**
35   *
36   */
37  public class EventEncoder extends AbstractStreamEncoder<ForkedProcessEventType>
38  {
39      public EventEncoder( WritableBufferedByteChannel out )
40      {
41          super( out );
42      }
43  
44      @Nonnull
45      @Override
46      protected final byte[] getEncodedMagicNumber()
47      {
48          return MAGIC_NUMBER_FOR_EVENTS_BYTES;
49      }
50  
51      @Nonnull
52      @Override
53      protected final byte[] enumToByteArray( @Nonnull ForkedProcessEventType e )
54      {
55          return e.getOpcodeBinary();
56      }
57  
58      @Nonnull
59      @Override
60      protected final byte[] getEncodedCharsetName()
61      {
62          return DEFAULT_STREAM_ENCODING_BYTES;
63      }
64  
65      @Nonnull
66      @Override
67      protected final Charset getCharset()
68      {
69          return DEFAULT_STREAM_ENCODING;
70      }
71  
72      @Nonnull
73      @Override
74      protected final CharsetEncoder newCharsetEncoder()
75      {
76          return getCharset().newEncoder();
77      }
78  }