/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/importcontacts/VcardImporter.java

  • Committer: Tim Marston
  • Date: 2013-12-08 18:43:52 UTC
  • Revision ID: tim@ed.am-20131208184352-0giww6zoy58bx07h
close some streams properly

Show diffs side-by-side

added added

removed removed

149
149
                                else if( line.matches( "(?i)END[ \t]*:[ \t]*VCARD.*" ) )
150
150
                                        in_vcard = false;
151
151
                        }
 
152
                        reader.close();
152
153
 
153
154
                }
154
155
                catch( FileNotFoundException e ) {
176
177
                        FileInputStream istream = new FileInputStream( file );
177
178
                        byte[] content = new byte[ (int)file.length() ];
178
179
                        istream.read( content );
179
 
                        istream = null;
 
180
                        istream.close();
180
181
 
181
182
                        // import
182
183
                        importVCardFileContent( content, file.getName() );
471
472
                private String extractCollonPartFromLine( ContentLine content_line,
472
473
                        boolean former )
473
474
                {
474
 
                        String ret = null;
475
 
 
476
475
                        // split line into name and value parts and check to make sure we
477
476
                        // only got 2 parts and that the first part is not zero in length
478
477
                        String[] parts = content_line.getUsAsciiLine().split( ":", 2 );
479
478
                        if( parts.length == 2 && parts[ 0 ].length() > 0 )
480
 
                                ret = parts[ former? 0 : 1 ];
 
479
                                return parts[ former? 0 : 1 ].trim();
481
480
 
482
 
                        return ret;
 
481
                        return null;
483
482
                }
484
483
 
485
484
                private String extractNameAndParamsFromLine( ContentLine content_line )
486
485
                {
487
 
                        return extractCollonPartFromLine( content_line, true ).trim();
 
486
                        return extractCollonPartFromLine( content_line, true );
488
487
                }
489
488
 
490
489
                private String extractValueFromLine( ContentLine content_line )
508
507
                                        name_and_params.equalsIgnoreCase( "VERSION" ) )
509
508
                                {
510
509
                                        // yes, get it!
511
 
                                        String value = extractValueFromLine( content_line ).trim();
512
 
                                        if( !value.equals( "2.1" ) && !value.equals( "3.0" ) )
 
510
                                        String value = extractValueFromLine( content_line );
 
511
                                        if( value == null || (
 
512
                                                !value.equals( "2.1" ) && !value.equals( "3.0" ) ) )
 
513
                                        {
513
514
                                                throw new ParseException( R.string.error_vcf_version );
 
515
                                        }
514
516
                                        _version = value;
515
517
 
516
518
                                        // parse any buffers we've been accumulating while we waited