diff options
author | Etienne Bergeron | 2013-12-10 14:53:26 +0000 |
---|---|---|
committer | Alexandre Montplaisir | 2013-12-12 03:03:11 +0000 |
commit | 2852a521cc4f990738c89c003f48c06aff64108a (patch) | |
tree | cdf074b069e84d3e41a2017b184831929f5962c4 | |
parent | 31d8ccc4fdae2fc66bb1ce403fc5e458b88630a2 (diff) | |
download | org.eclipse.linuxtools-2852a521cc4f990738c89c003f48c06aff64108a.tar.gz org.eclipse.linuxtools-2852a521cc4f990738c89c003f48c06aff64108a.tar.xz org.eclipse.linuxtools-2852a521cc4f990738c89c003f48c06aff64108a.zip |
ctf: tiny code refactoring in the metadata.
This pathch-set is a tiny cleanup before more refactoring.
The metadata are data and the "parsing/decoding/../" and
any actions on those data should be isolated in "internals"
and only accessors exposed to the user should be visible.
Patches to come soon.
Change-Id: Ie197726e16e0373e9a312b22ca9116968463990f
Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com>
Reviewed-on: https://git.eclipse.org/r/19585
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
2 files changed, 39 insertions, 45 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java index 84e88d9be1..24981914ed 100644 --- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java +++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/MetadataTest.java @@ -69,7 +69,7 @@ public class MetadataTest { * Test toString */ @Test - public void testToSting() { + public void testToString() { String result = fixture.toString(); assertNotNull(result); } diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java index 8fe1f602e4..c38eb1e5e2 100644 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java +++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java @@ -125,8 +125,6 @@ public class Metadata { * If there was a problem parsing the metadata */ public void parse() throws CTFReaderException { - CTFReaderException tempException = null; - FileInputStream fis = null; FileChannel metadataFileChannel = null; @@ -171,44 +169,40 @@ public class Metadata { gen.generate(); } catch (FileNotFoundException e) { - tempException = new CTFReaderException("Cannot find metadata file!"); //$NON-NLS-1$ + throw new CTFReaderException("Cannot find metadata file!"); //$NON-NLS-1$ } catch (IOException e) { /* This would indicate a problem with the ANTLR library... */ - tempException = new CTFReaderException(e); + throw new CTFReaderException(e); } catch (ParseException e) { - tempException = new CTFReaderException(e); + throw new CTFReaderException(e); } catch (RecognitionException e) { - tempException = new CtfAntlrException(e); + throw new CtfAntlrException(e); } catch (RewriteCardinalityException e){ - tempException = new CtfAntlrException(e); - } - - /* Ghetto resource management. Java 7 will deliver us from this... */ - if (metadataTextInput != null) { - try { - metadataTextInput.close(); - } catch (IOException e) { - // Do nothing + throw new CtfAntlrException(e); + } finally { + /* Ghetto resource management. Java 7 will deliver us from this... */ + if (metadataTextInput != null) { + try { + metadataTextInput.close(); + } catch (IOException e) { + // Do nothing + } } - } - if (metadataFileChannel != null) { - try { - metadataFileChannel.close(); - } catch (IOException e) { - // Do nothing + if (metadataFileChannel != null) { + try { + metadataFileChannel.close(); + } catch (IOException e) { + // Do nothing + } } - } - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - // Do nothing + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + // Do nothing + } } } - - if (tempException != null) { - throw tempException; - } } private static CommonTree createAST(Reader metadataTextInput) throws IOException, @@ -291,26 +285,28 @@ public class Metadata { ByteBuffer headerByteBuffer = ByteBuffer.allocate(METADATA_PACKET_HEADER_SIZE); /* Read the header */ - int nbBytesRead; try { - nbBytesRead = metadataFileChannel.read(headerByteBuffer); + int nbBytesRead = metadataFileChannel.read(headerByteBuffer); + + /* Return null if EOF */ + if (nbBytesRead < 0) { + return null; + } + + if (nbBytesRead != METADATA_PACKET_HEADER_SIZE) { + throw new CTFReaderException("Error reading the metadata header."); //$NON-NLS-1$ + } + } catch (IOException e) { throw new CTFReaderException("Error reading the metadata header.", e); //$NON-NLS-1$ } - /* Return null if EOF */ - if (nbBytesRead < 0) { - return null; - } - /* Set ByteBuffer's position to 0 */ headerByteBuffer.position(0); /* Use byte order that was detected with the magic number */ headerByteBuffer.order(detectedByteOrder); - assert (nbBytesRead == METADATA_PACKET_HEADER_SIZE); - MetadataPacketHeader header = new MetadataPacketHeader(); /* Read from the ByteBuffer */ @@ -334,10 +330,8 @@ public class Metadata { UUID uuid = Utils.makeUUID(header.uuid); if (!trace.uuidIsSet()) { trace.setUUID(uuid); - } else { - if (!trace.getUUID().equals(uuid)) { - throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$ - } + } else if (!trace.getUUID().equals(uuid)) { + throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$ } /* Extract the text from the packet */ |