Example usage for java.nio BufferUnderflowException printStackTrace

List of usage examples for java.nio BufferUnderflowException printStackTrace

Introduction

In this page you can find the example usage for java.nio BufferUnderflowException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:edu.cmu.cylab.starslinger.transaction.WebEngine.java

public static byte[] parseMessageResponse(byte[] resp) throws BufferUnderflowException {
    ByteBuffer buffer = ByteBuffer.wrap(resp);
    byte[] encfile = null;

    int errCode = buffer.getInt();
    if (errCode != 1)
        return null;

    int fileLen = buffer.getInt();
    encfile = new byte[fileLen];
    try {//from   w w  w  . j  ava  2  s .  c o m
        buffer.get(encfile);
        return encfile;
    } catch (BufferUnderflowException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.amaze.filemanager.utils.files.GenericCopyUtil.java

private void copyFile(FileChannel inChannel, BufferedOutputStream bufferedOutputStream) throws IOException {
    MappedByteBuffer inBuffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, mSourceFile.getSize());

    int count = -1;
    byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
    try {/*from   ww  w. j av a  2s  .  c om*/
        while (inBuffer.hasRemaining() && count != 0) {

            int tempPosition = inBuffer.position();

            try {

                // try normal way of getting bytes
                ByteBuffer tempByteBuffer = inBuffer.get(buffer);
                count = tempByteBuffer.position() - tempPosition;
            } catch (BufferUnderflowException exception) {
                exception.printStackTrace();

                // not enough bytes left in the channel to read, iterate over each byte and store
                // in the buffer

                // reset the counter bytes
                count = 0;
                for (int i = 0; i < buffer.length && inBuffer.hasRemaining(); i++) {
                    buffer[i] = inBuffer.get();
                    count++;
                }
            }

            if (count != -1 && !progressHandler.getCancelled()) {

                bufferedOutputStream.write(buffer, 0, count);
                ServiceWatcherUtil.position = inBuffer.position();
            } else
                break;

        }
    } finally {
        bufferedOutputStream.flush();
    }
}

From source file:edu.hawaii.soest.hioos.isus.ISUSFrame.java

public ISUSFrame(ByteBuffer isusFrame) {

    this.isusFrame = isusFrame;

    // parse each of the fields from the incoming byte buffer
    byte[] twoBytes = new byte[2];
    byte[] sixBytes = new byte[6];
    byte[] sevenBytes = new byte[7];
    byte[] fiveTwelveBytes = new byte[512];

    try {//from  ww  w .  j  av a 2s.  c  o  m

        // set the header field
        this.isusFrame.get(sixBytes);
        this.header.put(sixBytes);
        this.isusFrame.get(twoBytes);
        this.header.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.header.put(twoBytes);

        // set the sample date field
        this.isusFrame.get(twoBytes);
        this.sampleDate.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.sampleDate.put(twoBytes);

        // set the sample time field
        this.isusFrame.get(sixBytes);
        this.sampleTime.put(sixBytes);
        this.isusFrame.get(twoBytes);
        this.sampleTime.put(twoBytes);

        // set the nitrogen concentration field
        this.isusFrame.get(twoBytes);
        this.nitrogenConcentration.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.nitrogenConcentration.put(twoBytes);

        // set the first auxillary concentration field
        this.isusFrame.get(twoBytes);
        this.auxConcentration1.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.auxConcentration1.put(twoBytes);

        // set the second auxillary concentration field
        this.isusFrame.get(twoBytes);
        this.auxConcentration2.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.auxConcentration2.put(twoBytes);

        // set the third auxillary concentration field
        this.isusFrame.get(twoBytes);
        this.auxConcentration3.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.auxConcentration3.put(twoBytes);

        // set the root mean square error field
        this.isusFrame.get(twoBytes);
        this.rmsError.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.rmsError.put(twoBytes);

        // set the inside temperature field
        this.isusFrame.get(twoBytes);
        this.insideTemperature.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.insideTemperature.put(twoBytes);

        // set the spectrometer temperature field
        this.isusFrame.get(twoBytes);
        this.spectrometerTemperature.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.spectrometerTemperature.put(twoBytes);

        // set the lamp temperature field
        this.isusFrame.get(twoBytes);
        this.lampTemperature.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.lampTemperature.put(twoBytes);

        // set the lamp time field
        this.isusFrame.get(twoBytes);
        this.lampTime.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.lampTime.put(twoBytes);

        // set the humdity field
        this.isusFrame.get(twoBytes);
        this.humidity.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.humidity.put(twoBytes);

        // set the lamp voltage12 field
        this.isusFrame.get(twoBytes);
        this.lampVoltage12.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.lampVoltage12.put(twoBytes);

        // set the internal power voltage5 field
        this.isusFrame.get(twoBytes);
        this.internalPowerVoltage5.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.internalPowerVoltage5.put(twoBytes);

        // set the main power voltage field
        this.isusFrame.get(twoBytes);
        this.mainPowerVoltage.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.mainPowerVoltage.put(twoBytes);

        // set the reference average field
        this.isusFrame.get(twoBytes);
        this.referenceAverage.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.referenceAverage.put(twoBytes);

        // set the reference variance field
        this.isusFrame.get(twoBytes);
        this.referenceVariance.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.referenceVariance.put(twoBytes);

        // set the sea water dark counts field
        this.isusFrame.get(twoBytes);
        this.seaWaterDarkCounts.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.seaWaterDarkCounts.put(twoBytes);

        // set the average wavelength field
        this.isusFrame.get(twoBytes);
        this.spectrometerAverage.put(twoBytes);
        this.isusFrame.get(twoBytes);
        this.spectrometerAverage.put(twoBytes);

        // set the channel wavelengths field
        this.isusFrame.get(fiveTwelveBytes);
        this.channelWavelengths.put(fiveTwelveBytes);

        // set the checksum field
        this.checksum.put(this.isusFrame.get());

        // set the timestamp field
        this.isusFrame.get(sixBytes);
        this.timestamp.put(sixBytes);
        this.timestamp.put(this.isusFrame.get());

    } catch (BufferUnderflowException bue) {

        bue.printStackTrace();

    }
}