Skip to content

Commit

Permalink
WAVE: Improve message accuracy and code style
Browse files Browse the repository at this point in the history
  • Loading branch information
david-russo committed Mar 8, 2018
1 parent a27fcd2 commit 880dce4
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ public WaveModule() {
* Parses the content of a purported WAVE digital object and stores the
* results in RepInfo.
*
*
* @param stream
* An InputStream, positioned at its beginning, which is
* generated from the object to be parsed
Expand Down Expand Up @@ -354,7 +353,7 @@ else if (!firstFourChars.equals(RIFF_SIGNATURE)) {

// Get the length of the Form chunk. This includes all
// subsequent form fields and form subchunks, but excludes
// the form chunks's header (its ID and the its length).
// the form chunk's header (its ID and the its length).
long riffSize = readUnsignedInt(_dstream);
bytesRemaining = riffSize;

Expand Down Expand Up @@ -423,8 +422,7 @@ else if (!firstFourChars.equals(RIFF_SIGNATURE)) {
_aesMetadata.setDuration(sampleCount);
}

// Add note and label properties, if there's anything
// to report.
// Add note and label properties, if there's anything to report.
if (!_labels.isEmpty()) {
_propList.add(new Property("Labels", PropertyType.PROPERTY,
PropertyArity.LIST, _labels));
Expand Down Expand Up @@ -527,8 +525,9 @@ public void setBlockAlign(int align) {
}

/**
* Returns the ExifInfo object. If no ExifInfo object has been set, returns
* null.
* Returns the ExifInfo object.
*
* If no ExifInfo object has been set, returns <code>null</code>.
*/
public ExifInfo getExifInfo() {
return _exifInfo;
Expand Down Expand Up @@ -577,44 +576,39 @@ public void addListInfo(List l) {

/**
* One-argument version of <code>readSignedLong</code>. WAVE is always
* little-endian, so readSignedInt can unambiguously drop its endian
* argument.
* little-endian, so we can unambiguously drop its endian argument.
*/
public long readSignedLong(DataInputStream stream) throws IOException {
return readSignedLong(stream, false, this);
}

/**
* One-argument version of <code>readUnsignedInt</code>. WAVE is always
* little-endian, so readUnsignedInt can unambiguously drop its endian
* argument.
* little-endian, so we can unambiguously drop its endian argument.
*/
public long readUnsignedInt(DataInputStream stream) throws IOException {
return readUnsignedInt(stream, false, this);
}

/**
* One-argument version of <code>readSignedInt</code>. WAVE is always
* little-endian, so readSignedInt can unambiguously drop its endian
* argument.
* little-endian, so we can unambiguously drop its endian argument.
*/
public int readSignedInt(DataInputStream stream) throws IOException {
return readSignedInt(stream, false, this);
}

/**
* One-argument version of <code>readUnsignedShort</code>. WAVE is always
* little-endian, so readUnsignedShort can unambiguously drop its endian
* argument.
* little-endian, so we can unambiguously drop its endian argument.
*/
public int readUnsignedShort(DataInputStream stream) throws IOException {
return readUnsignedShort(stream, false, this);
}

/**
* One-argument version of <code>readSignedShort</code>. WAVE is always
* little-endian, so readSignedShort can unambiguously drop its endian
* argument.
* little-endian, so we can unambiguously drop its endian argument.
*/
public int readSignedShort(DataInputStream stream) throws IOException {
return readSignedShort(stream, false, this);
Expand All @@ -625,14 +619,15 @@ public int readSignedShort(DataInputStream stream) throws IOException {
* for ID's of various kinds.
*/
public String read4Chars(DataInputStream stream) throws IOException {
StringBuilder sbuf = new StringBuilder(4);
StringBuilder sb = new StringBuilder(4);
for (int i = 0; i < 4; i++) {
int ch = readUnsignedByte(stream, this);
// Omit nulls
if (ch != 0) {
sbuf.append((char) ch); // omit nulls
sb.append((char) ch);
}
}
return sbuf.toString();
return sb.toString();
}

/** Sets the WAVE codec. */
Expand Down Expand Up @@ -794,7 +789,7 @@ protected boolean readChunk(RepInfo info) throws IOException {
instrumentChunkSeen = true;
} else if ("mext".equals(chunkID)) {
if (mpegChunkSeen) {
dupChunkError(info, "MPEG");
dupChunkError(info, "MPEG Audio Extension");
}
chunk = new MpegChunk(this, chunkh, _dstream);
// I think only one MPEG chunk is allowed
Expand Down Expand Up @@ -825,7 +820,7 @@ protected boolean readChunk(RepInfo info) throws IOException {
linkChunkSeen = true;
} else if ("cue ".equals(chunkID)) {
if (cueChunkSeen) {
dupChunkError(info, "Cue");
dupChunkError(info, "Cue Points");
}
chunk = new CueChunk(this, chunkh, _dstream);
cueChunkSeen = true;
Expand Down Expand Up @@ -867,6 +862,7 @@ protected boolean readChunk(RepInfo info) throws IOException {
// Must come out to an even byte boundary
bytesRemaining -= skipBytes(_dstream, 1, this);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
/**********************************************************************
* Jhove - JSTOR/Harvard Object Validation Environment
* JHOVE - JSTOR/Harvard Object Validation Environment
* Copyright 2004 by JSTOR and the President and Fellows of Harvard College
**********************************************************************/

package edu.harvard.hul.ois.jhove.module.wave;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.*;
import edu.harvard.hul.ois.jhove.module.WaveModule;

import edu.harvard.hul.ois.jhove.*;
import edu.harvard.hul.ois.jhove.module.WaveModule;
import edu.harvard.hul.ois.jhove.module.iff.Chunk;
import edu.harvard.hul.ois.jhove.module.iff.ChunkHeader;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* Implementation of the WAVE Cue chunk, which defines cue
* Implementation of the WAVE Cue Points chunk, which defines cue
* points in an audio stream.
*
* @author Gary McGath
*
* @author Gary McGath
*/
public class CueChunk extends Chunk {

/**
* Constructor.
*
*
* @param module The WaveModule under which this was called
* @param hdr The header for this chunk
* @param dstrm The stream from which the WAVE data are being read
*/
public CueChunk(
ModuleBase module,
ChunkHeader hdr,
DataInputStream dstrm) {
ModuleBase module,
ChunkHeader hdr,
DataInputStream dstrm) {
super(module, hdr, dstrm);
}

/** Reads a chunk and puts a Cue property into
* the RepInfo object.
*
* @return <code>false</code> if the chunk is structurally
* invalid, otherwise <code>true</code>
/**
* Reads a chunk and puts a CuePoints property into the RepInfo object.
*
* @return <code>false</code> if the chunk is structurally invalid,
* otherwise <code>true</code>
*/
public boolean readChunk(RepInfo info) throws IOException {
WaveModule module = (WaveModule) _module;
int nPoints = (int) module.readUnsignedInt (_dstream);
List points = new ArrayList (nPoints);
int nPoints = (int) module.readUnsignedInt(_dstream);
List<Property> points = new ArrayList<>(nPoints);
for (int i = 0; i < nPoints; i++) {
// get unique ID for cue point structure
long dwIdent = module.readUnsignedInt (_dstream);
// get position in play order
long dwPos = module.readUnsignedInt (_dstream);
// chunk ID of referenced chunk ('data' or 'slnt')
String fccID = module.read4Chars (_dstream);
// Get unique ID for cue point
long dwIdent = module.readUnsignedInt(_dstream);
// Get position in play order
long dwPos = module.readUnsignedInt(_dstream);
// Get chunk ID of referenced chunk ('data' or 'slnt')
String fccID = module.read4Chars(_dstream);
// Get offset to start of chunk -- zero if a single
// Data chunk is used
long dwChunkStart = module.readUnsignedInt (_dstream);
long dwChunkStart = module.readUnsignedInt(_dstream);
// Get offset to start of block containing position
long dwBlockStart = module.readUnsignedInt (_dstream);
long dwBlockStart = module.readUnsignedInt(_dstream);
// Get offset from start of block to cue point.
// Note from the web page I'm using as a source:
// Unfortunately, the WAVE documentation is much too ambiguous,
Expand All @@ -70,36 +70,35 @@ public boolean readChunk(RepInfo info) throws IOException {
// Who knows? The guy who conjured up the Cue chunk certainly
// isn't saying. I'm assuming that it's a byte offset,
// like the above 2 fields.
long dwSampleOffset = module.readUnsignedInt (_dstream);
long dwSampleOffset = module.readUnsignedInt(_dstream);
Property[] cueProps = new Property[6];
cueProps[0] = new Property ("ID",
cueProps[0] = new Property("ID",
PropertyType.LONG,
new Long (dwIdent));
cueProps[1] = new Property ("Position",
dwIdent);
cueProps[1] = new Property("Position",
PropertyType.LONG,
new Long (dwPos));
cueProps[2] = new Property ("DataChunkID",
dwPos);
cueProps[2] = new Property("DataChunkID",
PropertyType.STRING,
fccID);
cueProps[3] = new Property("ChunkStart",
PropertyType.LONG,
new Long (dwChunkStart));
cueProps[4] = new Property ("BlockStart",
dwChunkStart);
cueProps[4] = new Property("BlockStart",
PropertyType.LONG,
new Long (dwBlockStart));
cueProps[5] = new Property ("SampleOffset",
dwBlockStart);
cueProps[5] = new Property("SampleOffset",
PropertyType.LONG,
dwSampleOffset);
points.add (new Property ("CuePoint",
points.add(new Property("CuePoint",
PropertyType.PROPERTY,
PropertyArity.ARRAY,
cueProps));
}
module.addWaveProperty(new Property ("Cue",
module.addWaveProperty(new Property("CuePoints",
PropertyType.PROPERTY,
PropertyArity.LIST,
points));
return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
/**********************************************************************
* Jhove - JSTOR/Harvard Object Validation Environment
* JHOVE - JSTOR/Harvard Object Validation Environment
* Copyright 2004 by JSTOR and the President and Fellows of Harvard College
**********************************************************************/

package edu.harvard.hul.ois.jhove.module.wave;

import java.io.DataInputStream;
import java.io.IOException;

import edu.harvard.hul.ois.jhove.*;
import edu.harvard.hul.ois.jhove.ModuleBase;
import edu.harvard.hul.ois.jhove.Property;
import edu.harvard.hul.ois.jhove.PropertyType;
import edu.harvard.hul.ois.jhove.RepInfo;
import edu.harvard.hul.ois.jhove.module.WaveModule;
import edu.harvard.hul.ois.jhove.module.iff.Chunk;
import edu.harvard.hul.ois.jhove.module.iff.ChunkHeader;

import java.io.DataInputStream;
import java.io.IOException;

/**
* Implementation of the WAVE Fact Chunk.
* The Fact chunk contains information specific to the
* compression scheme.
*
* @author Gary McGath
* The Fact chunk contains information specific to the compression scheme.
*
* @author Gary McGath
*/
public class FactChunk extends Chunk {

Expand All @@ -39,13 +41,14 @@ public FactChunk(
super(module, hdr, dstrm);
}

/** Reads a chunk and puts a Fact Property into
* the RepInfo object.
*
* @return <code>false</code> if the chunk is structurally
* invalid, otherwise <code>true</code>
/**
* Reads a chunk and puts a Fact Property into the RepInfo object.
*
* @return <code>false</code> if the chunk is structurally invalid,
* otherwise <code>true</code>
*/
public boolean readChunk(RepInfo info) throws IOException {

WaveModule module = (WaveModule) _module;

long sampleLength = module.readUnsignedInt(_dstream);
Expand Down
Loading

0 comments on commit 880dce4

Please sign in to comment.