Refactor class naming

This commit is contained in:
Jan Breuer 2015-10-09 11:33:33 +02:00
parent 01f5c61d4d
commit f49cc7a483
8 changed files with 47 additions and 34 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
*.ear *.ear
/build/ /build/
/nbproject/private/ /nbproject/private/
/dist/

View File

@ -53,7 +53,7 @@ javadoc.splitindex=true
javadoc.use=true javadoc.use=true
javadoc.version=false javadoc.version=false
javadoc.windowtitle= javadoc.windowtitle=
main.class=cz.jaybee.intelhex.IntelHexParserDemo main.class=cz.jaybee.cli.Hex2bin
manifest.file=manifest.mf manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false mkdist.disabled=false

View File

@ -23,8 +23,13 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package cz.jaybee.intelhex; package cz.jaybee.cli;
import cz.jaybee.intelhex.IntelHexException;
import cz.jaybee.intelhex.Parser;
import cz.jaybee.intelhex.Region;
import cz.jaybee.intelhex.listeners.RangeDetector;
import cz.jaybee.intelhex.listeners.BinWriter;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -37,17 +42,17 @@ import java.util.logging.Logger;
* *
* @author Jan Breuer * @author Jan Breuer
*/ */
public class IntelHexParserDemo { public class Hex2bin {
/** /**
* Convert Intel HEX to bin * Convert Intel HEX to bin
* *
* usage: * usage:
* *
* IntelHexParserDemo {source} {target} * Hex2bin {source} {target}
*
* Hex2bin {source} {target} {address_from} {address_to}
* *
* IntelHexParserDemo {source} {target} {address_from} {address_to}
*
* {source} is source Intel HEX file name * {source} is source Intel HEX file name
* *
* {target} is target BIN file name * {target} is target BIN file name
@ -69,7 +74,7 @@ public class IntelHexParserDemo {
if (args.length == 0) { if (args.length == 0) {
System.out.println("usage:"); System.out.println("usage:");
System.out.println(" hex2bin <hex> <bin> <start address> <end address> [minimize]"); System.out.println(" hex2bin <hex> <bin> <start address> <end address> [minimize]");
System.out.println(); System.out.println();
System.out.println(" full address range of app.hex"); System.out.println(" full address range of app.hex");
System.out.println(" hex2bin app.hex app.bin"); System.out.println(" hex2bin app.hex app.bin");
@ -82,7 +87,7 @@ public class IntelHexParserDemo {
System.out.println(" hex2bin app.hex app.bin 0x0000 0x1fff minimize"); System.out.println(" hex2bin app.hex app.bin 0x0000 0x1fff minimize");
return; return;
} }
if (args.length >= 1) { if (args.length >= 1) {
fileIn = args[0]; fileIn = args[0];
} }
@ -98,8 +103,8 @@ public class IntelHexParserDemo {
if (args.length >= 4) { if (args.length >= 4) {
dataTo = args[3]; dataTo = args[3];
} }
if (args.length >=5 ) { if (args.length >= 5) {
if (args[4].equals("minimize")) { if (args[4].equals("minimize")) {
minimize = true; minimize = true;
} }
@ -108,19 +113,19 @@ public class IntelHexParserDemo {
try (FileInputStream is = new FileInputStream(fileIn)) { try (FileInputStream is = new FileInputStream(fileIn)) {
OutputStream os = new FileOutputStream(fileOut); OutputStream os = new FileOutputStream(fileOut);
// init parser // init parser
IntelHexParser parser = new IntelHexParser(is); Parser parser = new Parser(is);
// 1st iteration - calculate maximum output range // 1st iteration - calculate maximum output range
RangeDetector rangeDetector = new RangeDetector(); RangeDetector rangeDetector = new RangeDetector();
parser.setDataListener(rangeDetector); parser.setDataListener(rangeDetector);
parser.parse(); parser.parse();
is.getChannel().position(0); is.getChannel().position(0);
Region outputRegion = rangeDetector.getFullRangeRegion(); Region outputRegion = rangeDetector.getFullRangeRegion();
// if address parameter is "max", calculate maximum memory region // if address parameter is "max", calculate maximum memory region
if (!("min".equals(dataFrom))) { if (!("min".equals(dataFrom))) {
outputRegion.setAddressStart(Long.parseLong(dataFrom.substring(2), 16)); outputRegion.setAddressStart(Long.parseLong(dataFrom.substring(2), 16));
} }
if (!("max".equals(dataTo))) { if (!("max".equals(dataTo))) {
outputRegion.setAddressEnd(Long.parseLong(dataTo.substring(2), 16)); outputRegion.setAddressEnd(Long.parseLong(dataTo.substring(2), 16));
} }
@ -137,10 +142,9 @@ public class IntelHexParserDemo {
System.out.print("Written output: "); System.out.print("Written output: ");
System.out.println(outputRegion); System.out.println(outputRegion);
} catch (IntelHexException | IOException ex) { } catch (IntelHexException | IOException ex) {
Logger.getLogger(IntelHexParserDemo.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Hex2bin.class.getName()).log(Level.SEVERE, null, ex);
} }
} }

View File

@ -30,7 +30,7 @@ package cz.jaybee.intelhex;
* *
* @author Jan Breuer * @author Jan Breuer
*/ */
public interface IntelHexDataListener { public interface DataListener {
/** /**
* Every time new data are read from file, this listener method is called * Every time new data are read from file, this listener method is called

View File

@ -34,10 +34,10 @@ import java.io.*;
* @author Kristian Sloth Lauszus * @author Kristian Sloth Lauszus
* @author riilabs * @author riilabs
*/ */
public class IntelHexParser { public class Parser {
private final BufferedReader reader; private final BufferedReader reader;
private IntelHexDataListener dataListener = null; private DataListener dataListener = null;
private static final int HEX = 16; private static final int HEX = 16;
private boolean eof = false; private boolean eof = false;
private int recordIdx = 0; private int recordIdx = 0;
@ -51,7 +51,7 @@ public class IntelHexParser {
int length; int length;
int address; int address;
IntelHexRecordType type; RecordType type;
byte[] data; byte[] data;
/** /**
@ -82,7 +82,7 @@ public class IntelHexParser {
* *
* @param reader * @param reader
*/ */
public IntelHexParser(Reader reader) { public Parser(Reader reader) {
this.reader = (reader instanceof BufferedReader) ? (BufferedReader) reader : new BufferedReader(reader); this.reader = (reader instanceof BufferedReader) ? (BufferedReader) reader : new BufferedReader(reader);
} }
@ -91,7 +91,7 @@ public class IntelHexParser {
* *
* @param stream * @param stream
*/ */
public IntelHexParser(InputStream stream) { public Parser(InputStream stream) {
this.reader = new BufferedReader(new InputStreamReader(stream)); this.reader = new BufferedReader(new InputStreamReader(stream));
} }
@ -100,7 +100,7 @@ public class IntelHexParser {
* *
* @param listener * @param listener
*/ */
public void setDataListener(IntelHexDataListener listener) { public void setDataListener(DataListener listener) {
this.dataListener = listener; this.dataListener = listener;
} }
@ -152,8 +152,8 @@ public class IntelHexParser {
result.address = ((hexRecord[1] & 0xFF) << 8) + (hexRecord[2] & 0xFF); result.address = ((hexRecord[1] & 0xFF) << 8) + (hexRecord[2] & 0xFF);
// determine record type // determine record type
result.type = IntelHexRecordType.fromInt(hexRecord[3] & 0xFF); result.type = RecordType.fromInt(hexRecord[3] & 0xFF);
if (result.type == IntelHexRecordType.UNKNOWN) { if (result.type == RecordType.UNKNOWN) {
throw new IntelHexException("Unsupported record type " + (hexRecord[3] & 0xFF) + " (" + recordIdx + ")"); throw new IntelHexException("Unsupported record type " + (hexRecord[3] & 0xFF) + " (" + recordIdx + ")");
} }
@ -219,6 +219,7 @@ public class IntelHexParser {
} else { } else {
throw new IntelHexException("Invalid START_SEG record at line #" + recordIdx + " " + record); throw new IntelHexException("Invalid START_SEG record at line #" + recordIdx + " " + record);
} }
break;
case UNKNOWN: case UNKNOWN:
break; break;
} }

View File

@ -30,7 +30,7 @@ package cz.jaybee.intelhex;
* *
* @author Jan Breuer * @author Jan Breuer
*/ */
public enum IntelHexRecordType { public enum RecordType {
DATA(0x00), DATA(0x00),
EOF(0x01), EOF(0x01),
@ -41,7 +41,7 @@ public enum IntelHexRecordType {
UNKNOWN(0xFF); UNKNOWN(0xFF);
int id; int id;
IntelHexRecordType(int id) { RecordType(int id) {
this.id = id; this.id = id;
} }
@ -60,12 +60,12 @@ public enum IntelHexRecordType {
* @param id record type integer value * @param id record type integer value
* @return record type enum value * @return record type enum value
*/ */
public static IntelHexRecordType fromInt(int id) { public static RecordType fromInt(int id) {
for (IntelHexRecordType d : IntelHexRecordType.values()) { for (RecordType d : RecordType.values()) {
if (d.id == id) { if (d.id == id) {
return d; return d;
} }
} }
return IntelHexRecordType.UNKNOWN; return RecordType.UNKNOWN;
} }
} }

View File

@ -23,8 +23,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package cz.jaybee.intelhex; package cz.jaybee.intelhex.listeners;
import cz.jaybee.intelhex.DataListener;
import cz.jaybee.intelhex.MemoryRegions;
import cz.jaybee.intelhex.Region;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays; import java.util.Arrays;
@ -36,7 +39,7 @@ import java.util.logging.Logger;
* *
* @author Jan Breuer * @author Jan Breuer
*/ */
public class BinWriter implements IntelHexDataListener { public class BinWriter implements DataListener {
private final Region outputRegion; private final Region outputRegion;
private final OutputStream destination; private final OutputStream destination;

View File

@ -23,7 +23,11 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
package cz.jaybee.intelhex; package cz.jaybee.intelhex.listeners;
import cz.jaybee.intelhex.DataListener;
import cz.jaybee.intelhex.MemoryRegions;
import cz.jaybee.intelhex.Region;
/** /**
* First pass listener to calculate data address range for further use * First pass listener to calculate data address range for further use
@ -31,7 +35,7 @@ package cz.jaybee.intelhex;
* @author riilabs * @author riilabs
* @author Jan Breuer * @author Jan Breuer
*/ */
public class RangeDetector implements IntelHexDataListener { public class RangeDetector implements DataListener {
private final MemoryRegions regions = new MemoryRegions(); private final MemoryRegions regions = new MemoryRegions();