List of usage examples for java.nio ByteOrder LITTLE_ENDIAN
ByteOrder LITTLE_ENDIAN
To view the source code for java.nio ByteOrder LITTLE_ENDIAN.
Click Source Link
From source file:org.pentaho.di.trans.steps.teradatabulkloader.TeraDataBulkLoaderRoutines.java
/** * Convert varchar.//from ww w . j a v a2 s .c o m * * @param string the string * @return the byte[] */ static byte[] convertVarchar(String string) { ByteBuffer b = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN); short strlen = 0; if (string != null) { strlen = (short) string.length(); b.putShort(strlen); } else { b = ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN); b.putShort((short) 0); return b.array(); } byte[] result = new byte[2 + strlen]; System.arraycopy(b.array(), 0, result, 0, 2); System.arraycopy(string.getBytes(), 0, result, 2, strlen); return result; }
From source file:org.pentaho.di.trans.steps.teradatabulkloader.TeraDataBulkLoaderRoutines.java
/** * Convert long.//from w w w .ja v a 2 s.c om * * @param integer the integer * @return the byte[] */ static byte[] convertLong(Long integer) { ByteBuffer b = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN); b.putLong(integer != null ? integer : 0); return b.array(); }
From source file:org.mycontroller.standalone.message.McMessageEngine.java
private void processFirmwareConfigRequest(McMessage mcMessage) { FirmwareConfigRequest firmwareConfigRequest = new FirmwareConfigRequest(); try {/* www . ja v a 2 s. c om*/ firmwareConfigRequest.setByteBuffer(ByteBuffer.wrap(Hex.decodeHex(mcMessage.getPayload().toCharArray())) .order(ByteOrder.LITTLE_ENDIAN), 0); boolean bootLoaderCommand = false; Firmware firmware = null; //Check firmware is configured for this particular node Node node = DaoUtils.getNodeDao().get(mcMessage.getGatewayId(), mcMessage.getNodeEui()); if (node != null && node.getEraseConfig() != null && node.getEraseConfig()) { bootLoaderCommand = true; _logger.debug("Erase EEPROM has been set..."); } else if (node != null && node.getFirmware() != null) { firmware = DaoUtils.getFirmwareDao().getById(node.getFirmware().getId()); _logger.debug("Firmware selected based on node configuration..."); } else if (firmwareConfigRequest.getType() == 65535 && firmwareConfigRequest.getVersion() == 65535) { if (AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware() != null) { firmware = DaoUtils.getFirmwareDao() .getById(AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware()); } else { _logger.warn("There is no default firmware set!"); } } else { firmware = DaoUtils.getFirmwareDao().get(firmwareConfigRequest.getType(), firmwareConfigRequest.getVersion()); } FirmwareConfigResponse firmwareConfigResponse = new FirmwareConfigResponse(); firmwareConfigResponse.setByteBufferPosition(0); if (bootLoaderCommand) {//If it is bootloader command if (node.getEraseConfig() != null && node.getEraseConfig()) { firmwareConfigResponse.loadEraseEepromCommand(); node.setEraseConfig(false); //Remove erase EEPROM flag and update in to database DaoUtils.getNodeDao().update(node); } else { _logger.warn("Selected booloader command is not available, FirmwareConfigRequest:[{}]", firmwareConfigRequest); return; } } else if (firmware == null) {//Non bootloader command if (AppProperties.getInstance().getMySensorsSettings().getEnbaledDefaultOnNoFirmware()) { _logger.debug("If requested firmware is not available, " + "redirect to default firmware is set, Checking the default firmware"); if (AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware() != null) { firmware = DaoUtils.getFirmwareDao() .getById(AppProperties.getInstance().getMySensorsSettings().getDefaultFirmware()); _logger.debug("Default firmware:[{}]", firmware.getFirmwareName()); } else { _logger.warn("There is no default firmware set!"); } } //Selected, default: No firmware available for this request if (firmware == null) { _logger.warn("Selected Firmware is not available, FirmwareConfigRequest:[{}]", firmwareConfigRequest); return; } } if (firmware != null) { firmwareConfigResponse.setType(firmware.getType().getId()); firmwareConfigResponse.setVersion(firmware.getVersion().getId()); firmwareConfigResponse.setBlocks(firmware.getBlocks()); firmwareConfigResponse.setCrc(firmware.getCrc()); } mcMessage.setTxMessage(true); mcMessage.setSubType(MESSAGE_TYPE_STREAM.ST_FIRMWARE_CONFIG_RESPONSE.getText()); mcMessage.setPayload(Hex.encodeHexString(firmwareConfigResponse.getByteBuffer().array()).toUpperCase()); McMessageUtils.sendToProviderBridge(mcMessage); _logger.debug("FirmwareConfigRequest:[{}]", firmwareConfigRequest); _logger.debug("FirmwareConfigResponse:[{}]", firmwareConfigResponse); } catch (DecoderException ex) { _logger.error("Exception, ", ex); } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.dta.DTAFileReader.java
private void decodeHeader(BufferedInputStream stream) throws IOException { dbgLog.fine("***** decodeHeader(): start *****"); if (stream == null) { throw new IllegalArgumentException("stream == null!"); }/*from w w w.j a v a 2 s .c om*/ dbgLog.fine("reading the header segument 1: 4 byte\n"); byte[] magic_number = new byte[DTA_MAGIC_NUMBER_LENGTH]; int nbytes = stream.read(magic_number, 0, DTA_MAGIC_NUMBER_LENGTH); if (nbytes == 0) { throw new IOException(); } if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("hex dump: 1st 4bytes =>" + new String(Hex.encodeHex(magic_number)) + "<-"); if (magic_number[2] != 1) { dbgLog.fine("3rd byte is not 1: given file is not stata-dta type"); throw new IllegalArgumentException("given file is not stata-dta type"); } else if ((magic_number[1] != 1) && (magic_number[1] != 2)) { dbgLog.fine("2nd byte is neither 0 nor 1: this file is not stata-dta type"); throw new IllegalArgumentException("given file is not stata-dta type"); } else if (!STATA_RELEASE_NUMBER.containsKey((int) magic_number[0])) { dbgLog.fine("1st byte (" + magic_number[0] + ") is not within the ingestable range [rel. 3-10]:" + "we cannot ingest this Stata file."); throw new IllegalArgumentException("given file is not stata-dta type"); } else { releaseNumber = (int) magic_number[0]; smd.getFileInformation().put("releaseNumber", releaseNumber); smd.getFileInformation().put("byteOrder", (int) magic_number[1]); smd.getFileInformation().put("OSByteOrder", ByteOrder.nativeOrder().toString()); smd.getFileInformation().put("mimeType", MIME_TYPE[0]); smd.getFileInformation().put("fileFormat", MIME_TYPE[0]); init(); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("this file is stata-dta type: " + STATA_RELEASE_NUMBER.get((int) magic_number[0]) + "(Number=" + magic_number[0] + ")"); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("Endian(file)(Big: 1; Little:2)=" + magic_number[1]); if ((int) magic_number[1] == 2) { isLittleEndian = true; dbgLog.fine("Reveral of the bytes is necessary to decode " + "multi-byte fields"); } if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("Endian of this platform:" + ByteOrder.nativeOrder().toString()); } dbgLog.fine("reading the remaining header segument 2: 60 or 109-byte"); byte[] header = new byte[headerLength]; nbytes = stream.read(header, 0, headerLength); //printHexDump(header, "header:\n"); // 1. number of variables: short (2 bytes) ByteBuffer bbnvar = ByteBuffer.wrap(header, 0, NVAR_FIELD_LENGTH); ByteBuffer dupnvar = bbnvar.duplicate(); short short_nvar = dupnvar.getShort(); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("get original short view(nvar)=" + short_nvar); if (isLittleEndian) { bbnvar.order(ByteOrder.LITTLE_ENDIAN); } short shrt_nvar = bbnvar.getShort(); smd.getFileInformation().put("varQnty", new Integer(shrt_nvar)); // setup variableTypeList int nvar = shrt_nvar; variableTypelList = new String[nvar]; // 2. number of observations: int (4 bytes) ByteBuffer nobs = ByteBuffer.wrap(header, NVAR_FIELD_LENGTH, NOBS_FIELD_LENGTH); ByteBuffer dupnobs = nobs.duplicate(); int int_dupnobs = dupnobs.getInt(); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("raw nobs=" + int_dupnobs); if (isLittleEndian) { nobs.order(ByteOrder.LITTLE_ENDIAN); } int int_nobs = nobs.getInt(); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("reversed nobs=" + int_nobs); smd.getFileInformation().put("caseQnty", new Integer(int_nobs)); // 3. data_label: 32 or 81 bytes int dl_offset = NVAR_FIELD_LENGTH + NOBS_FIELD_LENGTH; if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("dl_offset=" + dl_offset); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("data_label_length=" + dataLabelLength); String data_label = new String(Arrays.copyOfRange(header, dl_offset, (dl_offset + dataLabelLength)), "ISO-8859-1"); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("data_label_length=" + data_label.length()); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("loation of the null character=" + data_label.indexOf(0)); String dataLabel = getNullStrippedString(data_label); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("data_label_length=" + dataLabel.length()); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("data_label=[" + dataLabel + "]"); smd.getFileInformation().put("dataLabel", dataLabel); // 4. time_stamp: ASCII String (18 bytes) // added after release 4 if (releaseNumber > 104) { int ts_offset = dl_offset + dataLabelLength; String time_stamp = new String(Arrays.copyOfRange(header, ts_offset, ts_offset + TIME_STAMP_LENGTH), "ISO-8859-1"); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("time_stamp_length=" + time_stamp.length()); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("loation of the null character=" + time_stamp.indexOf(0)); String timeStamp = getNullStrippedString(time_stamp); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("timeStamp_length=" + timeStamp.length()); if (dbgLog.isLoggable(Level.FINE)) dbgLog.fine("timeStamp=[" + timeStamp + "]"); smd.getFileInformation().put("timeStamp", timeStamp); smd.getFileInformation().put("fileDate", timeStamp); smd.getFileInformation().put("fileTime", timeStamp); smd.getFileInformation().put("varFormat_schema", "STATA"); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("smd dump:" + smd.toString()); dbgLog.fine("***** decodeHeader(): end *****"); } }
From source file:ffx.xray.MTZFilter.java
public boolean readFcs(File mtzFile, ReflectionList reflectionlist, DiffractionRefinementData fcdata, CompositeConfiguration properties) { int nread, nignore, nres, nfriedel, ncut; ByteOrder b = ByteOrder.nativeOrder(); FileInputStream fis;//from w w w . ja v a 2 s.c om DataInputStream dis; StringBuilder sb = new StringBuilder(); try { fis = new FileInputStream(mtzFile); dis = new DataInputStream(fis); byte headeroffset[] = new byte[4]; byte bytes[] = new byte[80]; int offset = 0; // eat "MTZ" title dis.read(bytes, offset, 4); String mtzstr = new String(bytes); // header offset dis.read(headeroffset, offset, 4); // machine stamp dis.read(bytes, offset, 4); ByteBuffer bb = ByteBuffer.wrap(bytes); int stamp = bb.order(ByteOrder.BIG_ENDIAN).getInt(); String stampstr = Integer.toHexString(stamp); switch (stampstr.charAt(0)) { case '1': case '3': if (b.equals(ByteOrder.LITTLE_ENDIAN)) { b = ByteOrder.BIG_ENDIAN; } break; case '4': if (b.equals(ByteOrder.BIG_ENDIAN)) { b = ByteOrder.LITTLE_ENDIAN; } break; } bb = ByteBuffer.wrap(headeroffset); int headeroffseti = bb.order(b).getInt(); // skip to header and parse dis.skipBytes((headeroffseti - 4) * 4); for (Boolean parsing = true; parsing; dis.read(bytes, offset, 80)) { mtzstr = new String(bytes); parsing = parseHeader(mtzstr); } // column identifiers fc = phic = fs = phis = -1; boolean print = true; parseFcColumns(print); if (h < 0 || k < 0 || l < 0) { String message = "Fatal error in MTZ file - no H K L indexes?\n"; logger.log(Level.SEVERE, message); return false; } // reopen to start at beginning fis = new FileInputStream(mtzFile); dis = new DataInputStream(fis); // skip initial header dis.skipBytes(80); float data[] = new float[nColumns]; HKL mate = new HKL(); // read in data ComplexNumber c = new ComplexNumber(); nread = nignore = nres = nfriedel = ncut = 0; for (int i = 0; i < nReflections; i++) { for (int j = 0; j < nColumns; j++) { dis.read(bytes, offset, 4); bb = ByteBuffer.wrap(bytes); data[j] = bb.order(b).getFloat(); } int ih = (int) data[h]; int ik = (int) data[k]; int il = (int) data[l]; boolean friedel = reflectionlist.findSymHKL(ih, ik, il, mate, false); HKL hkl = reflectionlist.getHKL(mate); if (hkl != null) { if (fc > 0 && phic > 0) { c.re(data[fc] * cos(toRadians(data[phic]))); c.im(data[fc] * sin(toRadians(data[phic]))); fcdata.setFc(hkl.index(), c); } if (fs > 0 && phis > 0) { c.re(data[fs] * cos(toRadians(data[phis]))); c.im(data[fs] * sin(toRadians(data[phis]))); fcdata.setFs(hkl.index(), c); } nread++; } else { HKL tmp = new HKL(ih, ik, il); if (!reflectionlist.resolution .inInverseResSqRange(Crystal.invressq(reflectionlist.crystal, tmp))) { nres++; } else { nignore++; } } } sb.append(String.format(" MTZ file type (machine stamp): %s\n", stampstr)); sb.append(String.format(" Fc HKL read in: %d\n", nread)); sb.append(String.format(" Fc HKL read as friedel mates: %d\n", nfriedel)); sb.append(String.format(" Fc HKL NOT read in (too high resolution): %d\n", nres)); sb.append(String.format(" Fc HKL NOT read in (not in internal list?): %d\n", nignore)); sb.append(String.format(" Fc HKL NOT read in (F/sigF cutoff): %d\n", ncut)); sb.append(String.format(" HKL in internal list: %d\n", reflectionlist.hkllist.size())); if (logger.isLoggable(Level.INFO)) { logger.info(sb.toString()); } } catch (EOFException eof) { System.out.println("EOF reached "); return false; } catch (IOException ioe) { System.out.println("IO Exception: " + ioe.getMessage()); return false; } return true; }
From source file:org.pentaho.di.trans.steps.teradatabulkloader.TeraDataBulkLoaderRoutines.java
/** * Convert float.//from www .j a v a 2 s. c om * * @param d the d * @return the byte[] */ static byte[] convertFloat(Double d) { ByteBuffer b = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN); b.putDouble(d != null ? d : 0); return b.array(); }
From source file:com.moviejukebox.plugin.OpenSubtitlesPlugin.java
private static String getHash(File f) throws IOException { String s;/*ww w. j a v a2 s. co m*/ try ( // Open the file and then get a channel from the stream FileInputStream fis = new FileInputStream(f); FileChannel fc = fis.getChannel()) { long sz = fc.size(); if (sz < 65536) { fc.close(); fis.close(); return "NoHash"; } MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 65536); long sum = sz; bb.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < 65536 / 8; i++) { sum += bb.getLong();// sum(bb); } bb = fc.map(FileChannel.MapMode.READ_ONLY, sz - 65536, 65536); bb.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < 65536 / 8; i++) { sum += bb.getLong();// sum(bb); } sum = sum & 0xffffffffffffffffL; s = String.format("%016x", sum); } return s; }
From source file:com.mobilyzer.util.PhoneUtils.java
public String getWifiIpAddress() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { int ip = wifiInfo.getIpAddress(); if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ip = Integer.reverseBytes(ip); }/*from www. j a v a 2s .co m*/ byte[] bytes = BigInteger.valueOf(ip).toByteArray(); String address; try { address = InetAddress.getByAddress(bytes).getHostAddress(); return address; } catch (UnknownHostException e) { e.printStackTrace(); } } return null; }
From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.dta.DTAFileReader.java
private void decodeHeader(BufferedInputStream stream) throws IOException { dbgLog.fine("***** decodeHeader(): start *****"); if (stream == null) { throw new IllegalArgumentException("stream == null!"); }//from w ww . j a v a 2s .co m dbgLog.fine("reading the header segument 1: 4 byte\n"); byte[] magic_number = new byte[DTA_MAGIC_NUMBER_LENGTH]; int nbytes = stream.read(magic_number, 0, DTA_MAGIC_NUMBER_LENGTH); if (nbytes == 0) { throw new IOException(); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("hex dump: 1st 4bytes =>" + new String(Hex.encodeHex(magic_number)) + "<-"); } if (magic_number[2] != 1) { dbgLog.fine("3rd byte is not 1: given file is not stata-dta type"); throw new IllegalArgumentException("The file is not in a STATA format that we can read or support."); } else if ((magic_number[1] != 1) && (magic_number[1] != 2)) { dbgLog.fine("2nd byte is neither 0 nor 1: this file is not stata-dta type"); throw new IllegalArgumentException("given file is not stata-dta type"); } else if (!STATA_RELEASE_NUMBER.containsKey((int) magic_number[0])) { dbgLog.fine("1st byte (" + magic_number[0] + ") is not within the ingestable range [rel. 3-10]:" + "we cannot ingest this Stata file."); throw new IllegalArgumentException("given file is not stata-dta type"); } else { releaseNumber = magic_number[0]; init(); dataTable.setOriginalFileFormat(MIME_TYPE[0]); /* * releaseNumber: * for storing in the datatable, we are converting the numeric Stata * release number into a more user friendly "version number"; * e.g., "release number 115" = "Stata v. 12" * -- L.A. 4.0 */ dataTable.setOriginalFormatVersion(STATA_RELEASE_NUMBER.get(releaseNumber)); dataTable.setUnf("UNF:6:FILEFILEFILEFILE"); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("this file is stata-dta type: " + STATA_RELEASE_NUMBER.get(releaseNumber) + " (that means Stata version " + releaseNumber + ")"); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("Endian(file)(Big: 1; Little:2)=" + magic_number[1]); } /* * byte order: defined in the second byte of the "magic number": */ if (magic_number[1] == 2) { isLittleEndian = true; dbgLog.fine("Reversal of the bytes is necessary to decode " + "multi-byte fields"); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("Endian of this platform:" + ByteOrder.nativeOrder().toString()); } } dbgLog.fine("reading the remaining header segument 2: 60 or 109-byte"); byte[] header = new byte[headerLength]; nbytes = stream.read(header, 0, headerLength); // 1. number of variables: short (2 bytes) ByteBuffer bbnvar = ByteBuffer.wrap(header, 0, NVAR_FIELD_LENGTH); ByteBuffer dupnvar = bbnvar.duplicate(); short short_nvar = dupnvar.getShort(); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("get original short view(nvar)=" + short_nvar); } if (isLittleEndian) { bbnvar.order(ByteOrder.LITTLE_ENDIAN); } short shrt_nvar = bbnvar.getShort(); dataTable.setVarQuantity(new Long(shrt_nvar)); int nvar = shrt_nvar; if (dbgLog.isLoggable(Level.INFO)) { dbgLog.info("number of variables(nvar)=" + nvar); } // 4.0 Initialize dataverse variable objects: List<DataVariable> variableList = new ArrayList<>(); for (int i = 0; i < nvar; i++) { DataVariable dv = new DataVariable(); dv.setInvalidRanges(new ArrayList<>()); dv.setSummaryStatistics(new ArrayList<>()); dv.setUnf("UNF:6:XXX"); dv.setCategories(new ArrayList<>()); variableList.add(dv); dv.setFileOrder(i); dv.setDataTable(dataTable); } dataTable.setDataVariables(variableList); // setup variableTypeList variableTypes = new String[nvar]; // and the date/time format list: dateVariableFormats = new String[nvar]; // 2. number of observations: int (4 bytes) ByteBuffer nobs = ByteBuffer.wrap(header, NVAR_FIELD_LENGTH, NOBS_FIELD_LENGTH); ByteBuffer dupnobs = nobs.duplicate(); int int_dupnobs = dupnobs.getInt(); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("raw nobs=" + int_dupnobs); } if (isLittleEndian) { nobs.order(ByteOrder.LITTLE_ENDIAN); } int int_nobs = nobs.getInt(); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("reversed nobs=" + int_nobs); } // smd.getFileInformation().put("caseQnty", new Integer(int_nobs)); dataTable.setCaseQuantity(new Long(int_nobs)); /* the "data label" - note that we are not using this label for anything (wonder what it is though? can we use it somewhere?) but we still need to extract it from the byte stream, since the offsets of the objects stored further up are calculated relative to it. -- L.A., 4.0 */ // 3. data_label: 32 or 81 bytes int dl_offset = NVAR_FIELD_LENGTH + NOBS_FIELD_LENGTH; if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("dl_offset=" + dl_offset); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("data_label_length=" + dataLabelLength); } String data_label = new String(Arrays.copyOfRange(header, dl_offset, (dl_offset + dataLabelLength)), "ISO-8859-1"); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("data_label_length=" + data_label.length()); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("loation of the null character=" + data_label.indexOf(0)); } String dataLabel = getNullStrippedString(data_label); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("data_label_length=" + dataLabel.length()); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("data_label=[" + dataLabel + "]"); } // smd.getFileInformation().put("dataLabel", dataLabel); /* end of "data label" */ // 4. time_stamp: ASCII String (18 bytes) // added after release 4 if (releaseNumber > 104) { int ts_offset = dl_offset + dataLabelLength; String time_stamp = new String(Arrays.copyOfRange(header, ts_offset, ts_offset + TIME_STAMP_LENGTH), "ISO-8859-1"); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("time_stamp_length=" + time_stamp.length()); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("loation of the null character=" + time_stamp.indexOf(0)); } String timeStamp = getNullStrippedString(time_stamp); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("timeStamp_length=" + timeStamp.length()); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("timeStamp=[" + timeStamp + "]"); } } }
From source file:ffx.xray.parsers.MTZFilter.java
/** * Read the structure factors./*from ww w.ja v a 2s.c o m*/ * * @param mtzFile * @param reflectionList * @param fcData * @param properties * @return */ public boolean readFcs(File mtzFile, ReflectionList reflectionList, DiffractionRefinementData fcData, CompositeConfiguration properties) { int nRead, nIgnore, nRes, nFriedel, nCut; ByteOrder byteOrder = ByteOrder.nativeOrder(); FileInputStream fileInputStream; DataInputStream dataInputStream; StringBuilder sb = new StringBuilder(); try { fileInputStream = new FileInputStream(mtzFile); dataInputStream = new DataInputStream(fileInputStream); byte headerOffset[] = new byte[4]; byte bytes[] = new byte[80]; int offset = 0; // Eat "MTZ" title. dataInputStream.read(bytes, offset, 4); String mtzString = null; // Header offset. dataInputStream.read(headerOffset, offset, 4); // Machine stamp. dataInputStream.read(bytes, offset, 4); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); int stamp = byteBuffer.order(ByteOrder.BIG_ENDIAN).getInt(); String stampString = Integer.toHexString(stamp); switch (stampString.charAt(0)) { case '1': case '3': if (byteOrder.equals(ByteOrder.LITTLE_ENDIAN)) { byteOrder = ByteOrder.BIG_ENDIAN; } break; case '4': if (byteOrder.equals(ByteOrder.BIG_ENDIAN)) { byteOrder = ByteOrder.LITTLE_ENDIAN; } break; } byteBuffer = ByteBuffer.wrap(headerOffset); int headerOffsetI = byteBuffer.order(byteOrder).getInt(); // Skip to header and parse. dataInputStream.skipBytes((headerOffsetI - 4) * 4); for (Boolean parsing = true; parsing; dataInputStream.read(bytes, offset, 80)) { mtzString = new String(bytes); parsing = parseHeader(mtzString); } // Column identifiers. fc = phiC = fs = phiS = -1; boolean print = true; parseFcColumns(print); if (h < 0 || k < 0 || l < 0) { String message = " Fatal error in MTZ file - no H K L indexes?\n"; logger.log(Level.SEVERE, message); return false; } // Reopen to start at beginning. fileInputStream = new FileInputStream(mtzFile); dataInputStream = new DataInputStream(fileInputStream); // Skip initial header. dataInputStream.skipBytes(80); float data[] = new float[nColumns]; HKL mate = new HKL(); // Read in data. ComplexNumber complexNumber = new ComplexNumber(); nRead = nIgnore = nRes = nFriedel = nCut = 0; for (int i = 0; i < nReflections; i++) { for (int j = 0; j < nColumns; j++) { dataInputStream.read(bytes, offset, 4); byteBuffer = ByteBuffer.wrap(bytes); data[j] = byteBuffer.order(byteOrder).getFloat(); } int ih = (int) data[h]; int ik = (int) data[k]; int il = (int) data[l]; boolean friedel = reflectionList.findSymHKL(ih, ik, il, mate, false); HKL hkl = reflectionList.getHKL(mate); if (hkl != null) { if (fc > 0 && phiC > 0) { complexNumber.re(data[fc] * cos(toRadians(data[phiC]))); complexNumber.im(data[fc] * sin(toRadians(data[phiC]))); fcData.setFc(hkl.index(), complexNumber); } if (fs > 0 && phiS > 0) { complexNumber.re(data[fs] * cos(toRadians(data[phiS]))); complexNumber.im(data[fs] * sin(toRadians(data[phiS]))); fcData.setFs(hkl.index(), complexNumber); } nRead++; } else { HKL tmp = new HKL(ih, ik, il); if (!reflectionList.resolution .inInverseResSqRange(Crystal.invressq(reflectionList.crystal, tmp))) { nRes++; } else { nIgnore++; } } } if (logger.isLoggable(Level.INFO)) { sb.append(format(" MTZ file type (machine stamp): %s\n", stampString)); sb.append(format(" Fc HKL read in: %d\n", nRead)); sb.append(format(" Fc HKL read as friedel mates: %d\n", nFriedel)); sb.append(format(" Fc HKL NOT read in (too high resolution): %d\n", nRes)); sb.append(format(" Fc HKL NOT read in (not in internal list?): %d\n", nIgnore)); sb.append(format(" Fc HKL NOT read in (F/sigF cutoff): %d\n", nCut)); sb.append( format(" HKL in internal list: %d\n", reflectionList.hkllist.size())); logger.info(sb.toString()); } } catch (EOFException e) { String message = " MTZ end of file reached."; logger.log(Level.WARNING, message, e); return false; } catch (IOException e) { String message = " MTZ IO Exception."; logger.log(Level.WARNING, message, e); return false; } return true; }