1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package java.nio.charset;
18 
19 /**
20  * Used to indicate what kind of actions to take in case of encoding/decoding
21  * errors. Currently three actions are defined: {@code IGNORE}, {@code REPLACE}
22  * and {@code REPORT}.
23  */
24 public class CodingErrorAction {
25 
26     /**
27      * Denotes the action to ignore any errors.
28      */
29     public static final CodingErrorAction IGNORE = new CodingErrorAction(
30             "IGNORE");
31 
32     /**
33      * Denotes the action to fill in the output with a replacement character
34      * when malformed input or an unmappable character is encountered.
35      */
36     public static final CodingErrorAction REPLACE = new CodingErrorAction(
37             "REPLACE");
38 
39     /**
40      * Denotes the action to report the encountered error in an appropriate
41      * manner, for example to throw an exception or return an informative
42      * result.
43      */
44     public static final CodingErrorAction REPORT = new CodingErrorAction(
45             "REPORT");
46 
47     // The name of this action
48     private String action;
49 
50     /*
51      * Can't instantiate outside.
52      */
CodingErrorAction(String action)53     private CodingErrorAction(String action) {
54         this.action = action;
55     }
56 
57     /**
58      * Returns a text description of this action indication.
59      *
60      * @return a text description of this action indication.
61      */
62     @Override
toString()63     public String toString() {
64         return "Action: " + this.action;
65     }
66 }
67