ucar.unidata.io.RandomAccessFile.writeInt()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中ucar.unidata.io.RandomAccessFile.writeInt方法的一些代码示例,展示了RandomAccessFile.writeInt的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RandomAccessFile.writeInt方法的具体详情如下:
包路径:ucar.unidata.io.RandomAccessFile
类名称:RandomAccessFile
方法名:writeInt

RandomAccessFile.writeInt介绍

[英]Writes an int to the file as four bytes, high byte first.
[中]将int作为四个字节写入文件,高字节优先。

代码示例

代码示例来源:origin: edu.ucar/netcdf

/**
 * Write an array of ints
 *
 * @param pa    write from this array
 * @param start starting with this element in the array
 * @param n     write this number of elements
 * @throws IOException on read error
 */
public final void writeInt(int[] pa, int start, int n) throws IOException {
 for (int i = 0; i < n; i++) {
  writeInt(pa[start + i]);
 }
}

代码示例来源:origin: Unidata/thredds

/**
 * Write an array of ints
 *
 * @param pa    write from this array
 * @param start starting with this element in the array
 * @param n     write this number of elements
 * @throws IOException on read error
 */
public final void writeInt(int[] pa, int start, int n) throws IOException {
 for (int i = 0; i < n; i++) {
  writeInt(pa[start + i]);
 }
}

代码示例来源:origin: edu.ucar/cdm

/**
 * Write an array of ints
 *
 * @param pa    write from this array
 * @param start starting with this element in the array
 * @param n     write this number of elements
 * @throws IOException on read error
 */
public final void writeInt(int[] pa, int start, int n) throws IOException {
 for (int i = 0; i < n; i++) {
  writeInt(pa[start + i]);
 }
}

代码示例来源:origin: edu.ucar/unidataCommon

/**
 * Write an array of ints
 *
 * @param pa    write from this array
 * @param start starting with this element in the array
 * @param n     write this number of elements
 * @throws IOException on read error
 */
public final void writeInt(int[] pa, int start, int n) throws IOException {
 for (int i = 0; i < n; i++) {
  writeInt(pa[start + i]);
 }
}

代码示例来源:origin: Unidata/thredds

/**
 * Converts the float argument to an <code>int</code> using the
 * <code>floatToIntBits</code> method in class <code>Float</code>,
 * and then writes that <code>int</code> value to the file as a
 * 4-byte quantity, high byte first.
 *
 * @param v a <code>float</code> value to be written.
 * @throws IOException if an I/O error occurs.
 * @see java.lang.Float#floatToIntBits(float)
 */
public final void writeFloat(float v) throws IOException {
 writeInt(Float.floatToIntBits(v));
}

代码示例来源:origin: edu.ucar/netcdf

/**
 * Converts the float argument to an <code>int</code> using the
 * <code>floatToIntBits</code> method in class <code>Float</code>,
 * and then writes that <code>int</code> value to the file as a
 * 4-byte quantity, high byte first.
 *
 * @param v a <code>float</code> value to be written.
 * @throws IOException if an I/O error occurs.
 * @see java.lang.Float#floatToIntBits(float)
 */
public final void writeFloat(float v) throws IOException {
 writeInt(Float.floatToIntBits(v));
}

代码示例来源:origin: edu.ucar/cdm

/**
 * Converts the float argument to an <code>int</code> using the
 * <code>floatToIntBits</code> method in class <code>Float</code>,
 * and then writes that <code>int</code> value to the file as a
 * 4-byte quantity, high byte first.
 *
 * @param v a <code>float</code> value to be written.
 * @throws IOException if an I/O error occurs.
 * @see java.lang.Float#floatToIntBits(float)
 */
public final void writeFloat(float v) throws IOException {
 writeInt(Float.floatToIntBits(v));
}

代码示例来源:origin: edu.ucar/unidataCommon

/**
 * Converts the float argument to an <code>int</code> using the
 * <code>floatToIntBits</code> method in class <code>Float</code>,
 * and then writes that <code>int</code> value to the file as a
 * 4-byte quantity, high byte first.
 *
 * @param v a <code>float</code> value to be written.
 * @throws IOException if an I/O error occurs.
 * @see java.lang.Float#floatToIntBits(float)
 */
public final void writeFloat(float v) throws IOException {
 writeInt(Float.floatToIntBits(v));
}

代码示例来源:origin: Unidata/thredds

void writeNumrecs() throws IOException {
 // set number of records in the header
 raf.seek(4);
 raf.writeInt(numrecs);
}

代码示例来源:origin: edu.ucar/netcdf

void writeNumrecs() throws IOException {
 // set number of records in the header
 raf.seek(4);
 raf.writeInt(numrecs);
}

代码示例来源:origin: edu.ucar/cdm

void writeNumrecs() throws IOException {
 // set number of records in the header
 raf.seek(4);
 raf.writeInt(numrecs);
}

代码示例来源:origin: edu.ucar/cdm

private void writeString(String s) throws IOException {
//   if (s.length() == 0)
 //   System.out.println("HEY");
 byte[] b = s.getBytes(CDM.utf8Charset); // all strings are encoded in UTF-8 Unicode.
 raf.writeInt(b.length);
 raf.write(b);
 pad(b.length, (byte) 0);
}

代码示例来源:origin: edu.ucar/netcdf

private void writeString(String s) throws IOException {
//   if (s.length() == 0)
 //   System.out.println("HEY");
 byte[] b = s.getBytes(CDM.utf8Charset); // all strings are encoded in UTF-8 Unicode.
 raf.writeInt(b.length);
 raf.write(b);
 pad(b.length, (byte) 0);
}

代码示例来源:origin: Unidata/thredds

private void writeString(String s) throws IOException {
//   if (s.length() == 0)
 //   System.out.println("HEY");
 byte[] b = s.getBytes(CDM.utf8Charset); // all strings are encoded in UTF-8 Unicode.
 raf.writeInt(b.length);
 raf.write(b);
 pad(b.length, (byte) 0);
}

代码示例来源:origin: edu.ucar/netcdf

private int writeAttributeValue(Number numValue) throws IOException {
 if (numValue instanceof Byte) {
  raf.write(numValue.byteValue());
  return 1;
 } else if (numValue instanceof Short) {
  raf.writeShort(numValue.shortValue());
  return 2;
 } else if (numValue instanceof Integer) {
  raf.writeInt(numValue.intValue());
  return 4;
 } else if (numValue instanceof Float) {
  raf.writeFloat(numValue.floatValue());
  return 4;
 } else if (numValue instanceof Double) {
  raf.writeDouble(numValue.doubleValue());
  return 8;
 }
 throw new IllegalStateException("unknown attribute type == " + numValue.getClass().getName());
}

代码示例来源:origin: edu.ucar/cdm

private int writeAttributeValue(Number numValue) throws IOException {
 if (numValue instanceof Byte) {
  raf.write(numValue.byteValue());
  return 1;
 } else if (numValue instanceof Short) {
  raf.writeShort(numValue.shortValue());
  return 2;
 } else if (numValue instanceof Integer) {
  raf.writeInt(numValue.intValue());
  return 4;
 } else if (numValue instanceof Float) {
  raf.writeFloat(numValue.floatValue());
  return 4;
 } else if (numValue instanceof Double) {
  raf.writeDouble(numValue.doubleValue());
  return 8;
 }
 throw new IllegalStateException("unknown attribute type == " + numValue.getClass().getName());
}

代码示例来源:origin: Unidata/thredds

private int writeAttributeValue(Number numValue) throws IOException {
 if (numValue instanceof Byte) {
  raf.write(numValue.byteValue());
  return 1;
 } else if (numValue instanceof Short) {
  raf.writeShort(numValue.shortValue());
  return 2;
 } else if (numValue instanceof Integer) {
  raf.writeInt(numValue.intValue());
  return 4;
 } else if (numValue instanceof Float) {
  raf.writeFloat(numValue.floatValue());
  return 4;
 } else if (numValue instanceof Double) {
  raf.writeDouble(numValue.doubleValue());
  return 8;
 }
 throw new IllegalStateException("unknown attribute type == " + numValue.getClass().getName());
}

代码示例来源:origin: edu.ucar/cdm

private void writeAtts(List<Attribute> atts, Formatter fout) throws IOException {
 int n = atts.size();
 if (n == 0) {
  raf.writeInt(0);
  raf.writeInt(0);
 } else {
  raf.writeInt(MAGIC_ATT);
  raf.writeInt(n);
 }
 for (int i = 0; i < n; i++) {
  if (fout != null) fout.format("***att %d pos= %d%n", i, raf.getFilePointer());
  Attribute att = atts.get(i);
  writeString(att.getShortName());
  int type = getType(att.getDataType());
  raf.writeInt(type);
  if (type == 2) {
   writeStringValues(att);
  } else {
   int nelems = att.getLength();
   raf.writeInt(nelems);
   int nbytes = 0;
   for (int j = 0; j < nelems; j++)
    nbytes += writeAttributeValue(att.getNumericValue(j));
   pad(nbytes, (byte) 0);
   if (fout != null) fout.format(" end write val pos= %d%n", raf.getFilePointer());
  }
  if (fout != null) fout.format("  %s%n", att);
 }
}

代码示例来源:origin: Unidata/thredds

private void writeAtts(List<Attribute> atts, Formatter fout) throws IOException {
 int n = atts.size();
 if (n == 0) {
  raf.writeInt(0);
  raf.writeInt(0);
 } else {
  raf.writeInt(MAGIC_ATT);
  raf.writeInt(n);
 }
 for (int i = 0; i < n; i++) {
  if (fout != null) fout.format("***att %d pos= %d%n", i, raf.getFilePointer());
  Attribute att = atts.get(i);
  writeString(att.getShortName());
  int type = getType(att.getDataType());
  raf.writeInt(type);
  if (type == 2) {
   writeStringValues(att);
  } else {
   int nelems = att.getLength();
   raf.writeInt(nelems);
   int nbytes = 0;
   for (int j = 0; j < nelems; j++)
    nbytes += writeAttributeValue(att.getNumericValue(j));
   pad(nbytes, (byte) 0);
   if (fout != null) fout.format(" end write val pos= %d%n", raf.getFilePointer());
  }
  if (fout != null) fout.format("  %s%n", att);
 }
}

代码示例来源:origin: edu.ucar/netcdf

private void writeAtts(List<Attribute> atts, Formatter fout) throws IOException {
 int n = atts.size();
 if (n == 0) {
  raf.writeInt(0);
  raf.writeInt(0);
 } else {
  raf.writeInt(MAGIC_ATT);
  raf.writeInt(n);
 }
 for (int i = 0; i < n; i++) {
  if (fout != null) fout.format("***att %d pos= %d\n", i, raf.getFilePointer());
  Attribute att = atts.get(i);
  writeString(att.getShortName());
  int type = getType(att.getDataType());
  raf.writeInt(type);
  if (type == 2) {
   writeStringValues(att);
  } else {
   int nelems = att.getLength();
   raf.writeInt(nelems);
   int nbytes = 0;
   for (int j = 0; j < nelems; j++)
    nbytes += writeAttributeValue(att.getNumericValue(j));
   pad(nbytes, (byte) 0);
   if (fout != null) fout.format(" end write val pos= %d\n", raf.getFilePointer());
  }
  if (fout != null) fout.format("  %s\n", att);
 }
}

相关文章