Changeset 30864 in osm


Ignore:
Timestamp:
2014-12-19T18:06:07+01:00 (10 years ago)
Author:
donvip
Message:

[josm_czechaddress] keep causes of exceptions

Location:
applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/DatabaseLoadException.java

    r23190 r30864  
    1919    /**
    2020     * Default constructor, which sets the message description.
    21      * @param message message to be shown to user
     21     * @param  message the detail message (which is saved for later retrieval
     22     *         by the {@link #getMessage()} method).
    2223     */
    2324    public DatabaseLoadException(String message) {
    2425        super(message);
    2526    }
     27
     28    /**
     29     * Default constructor, which sets the message description and cause.
     30     * @param  message the detail message (which is saved for later retrieval
     31     *         by the {@link #getMessage()} method).
     32     * @param  cause the cause (which is saved for later retrieval by the
     33     *         {@link #getCause()} method).  (A <tt>null</tt> value is
     34     *         permitted, and indicates that the cause is nonexistent or
     35     *         unknown.)
     36     */
     37    public DatabaseLoadException(String message, Throwable cause) {
     38        super(message, cause);
     39    }
    2640}
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/DatabaseParser.java

    r30861 r30864  
    111111
    112112            try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(getDatabasePath()))) {
    113                     int total = 0, count;
    114                     byte[] buffer = new byte[1024*512];
    115                     while ((count = con.getInputStream().read(buffer)) >= 0) {
    116                         bos.write(buffer, 0, count);
    117                         total += count;
    118                         Main.error("CzechAddress: MVČR database: " + String.valueOf(total/1024) + " kb downloaded.");
    119                     }
     113                int total = 0, count;
     114                byte[] buffer = new byte[1024*512];
     115                while ((count = con.getInputStream().read(buffer)) >= 0) {
     116                    bos.write(buffer, 0, count);
     117                    total += count;
     118                    Main.error("CzechAddress: MVČR database: " + String.valueOf(total/1024) + " kb downloaded.");
     119                }
    120120            }
    121121
     
    128128
    129129        } catch (IOException ioexp) {
    130             ioexp.printStackTrace();
    131             throw new DatabaseLoadException("Chyba při načítání databáze");
     130            throw new DatabaseLoadException("Chyba při načítání databáze", ioexp);
    132131        }
    133132    }
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/MvcrParser.java

    r30346 r30864  
    99import java.util.zip.ZipEntry;
    1010import java.util.zip.ZipInputStream;
     11
    1112import org.openstreetmap.josm.Main;
    1213import org.openstreetmap.josm.plugins.czechaddress.DatabaseLoadException;
     
    3839//==============================================================================
    3940
     41    @Override
    4042    public void startElement(String uri, String localName, String name,
    4143                                Attributes attributes) throws SAXException {
     
    176178    }
    177179
     180    @Override
    178181    public void setDocumentLocator(Locator locator) {}
     182    @Override
    179183    public void startDocument() throws SAXException {}
     184    @Override
    180185    public void endDocument() throws SAXException {}
     186    @Override
    181187    public void startPrefixMapping(String prefix, String uri) throws SAXException {}
     188    @Override
    182189    public void endPrefixMapping(String prefix) throws SAXException {}
     190    @Override
    183191    public void characters(char[] ch, int start, int length) throws SAXException {}
     192    @Override
    184193    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {}
     194    @Override
    185195    public void processingInstruction(String target, String data) throws SAXException {}
     196    @Override
    186197    public void skippedEntity(String name) throws SAXException {}
    187198
     
    237248    }
    238249
     250    @Override
    239251    protected InputStream getDatabaseStream() throws DatabaseLoadException {
    240252        ZipInputStream zis;
    241253        ZipEntry zipEntry = null;
    242254        try {
    243         zis = new ZipInputStream(new FileInputStream(getDatabasePath()));
    244 
    245         while ((zipEntry = zis.getNextEntry()) != null)
    246             if (zipEntry.getName().equals("adresy.xml"))
    247                 break;
     255            zis = new ZipInputStream(new FileInputStream(getDatabasePath()));
     256
     257            while ((zipEntry = zis.getNextEntry()) != null)
     258                if (zipEntry.getName().equals("adresy.xml"))
     259                    break;
    248260
    249261        } catch (IOException ioexp) {
    250             throw new DatabaseLoadException("Chyba při čtení archivu s databází.");
     262            throw new DatabaseLoadException("Chyba při čtení archivu s databází.", ioexp);
    251263        }
    252264
    253265        if (zipEntry == null)
    254         throw new DatabaseLoadException(
     266            throw new DatabaseLoadException(
    255267                    "ZIP archiv s databází neobsahuje soubor 'adresy.xml'.");
    256268
  • applications/editors/josm/plugins/czechaddress/src/org/openstreetmap/josm/plugins/czechaddress/parser/XMLParser.java

    r15585 r30864  
    22
    33import java.io.IOException;
     4
    45import org.openstreetmap.josm.plugins.czechaddress.DatabaseLoadException;
     6import org.openstreetmap.josm.plugins.czechaddress.addressdatabase.Database;
    57import org.xml.sax.ContentHandler;
    68import org.xml.sax.InputSource;
     
    2224                                implements ContentHandler {
    2325
     26    @Override
    2427    protected void parseDatabase() throws DatabaseLoadException {
    2528
     
    3134
    3235        } catch (IOException ioexp) {
    33             throw new DatabaseLoadException("Chyba při čtení archivu s databází.");
     36            throw new DatabaseLoadException("Chyba při čtení archivu s databází.", ioexp);
    3437        } catch (SAXException saxexp) {
    35             throw new DatabaseLoadException("Selhaho parsování XML souboru s databází adres.");
     38            throw new DatabaseLoadException("Selhaho parsování XML souboru s databází adres.", saxexp);
    3639        }
    3740    }
Note: See TracChangeset for help on using the changeset viewer.