br.com.objectos.way.io.WayIOLineException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of way-io Show documentation
Show all versions of way-io Show documentation
CSV, XLS and fixed parsers
The newest version!
/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* Licensed 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.
*/
package br.com.objectos.way.io;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
import br.com.objectos.comuns.io.Line;
/**
* @author [email protected] (Marcio Endo)
*/
class WayIOLineException extends WayIOException {
private static final long serialVersionUID = 1L;
private final Line line;
WayIOLineException(Line line, String message) {
super(message);
this.line = line;
}
WayIOLineException(Line line, String message, Throwable cause) {
super(message, cause);
this.line = line;
}
@Override
public String getMessage() {
StringWriter sw = new StringWriter();
BufferedWriter writer = new BufferedWriter(sw);
try {
writer.write("Could not parse a line:");
writer.newLine();
writer.write(line.getText());
writer.newLine();
writer.newLine();
writer.write("With the following error message:");
writer.newLine();
writer.write(getMsg());
writer.flush();
return sw.toString();
} catch (IOException e) {
return super.getMessage();
} finally {
try {
writer.close();
} catch (IOException e) {
// can't really do much.
}
}
}
public Line getLine() {
return line;
}
protected String getMsg() {
return super.getMessage();
}
}