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

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

本文整理了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

  1. /**
  2. * Write an array of ints
  3. *
  4. * @param pa write from this array
  5. * @param start starting with this element in the array
  6. * @param n write this number of elements
  7. * @throws IOException on read error
  8. */
  9. public final void writeInt(int[] pa, int start, int n) throws IOException {
  10. for (int i = 0; i < n; i++) {
  11. writeInt(pa[start + i]);
  12. }
  13. }

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

  1. /**
  2. * Write an array of ints
  3. *
  4. * @param pa write from this array
  5. * @param start starting with this element in the array
  6. * @param n write this number of elements
  7. * @throws IOException on read error
  8. */
  9. public final void writeInt(int[] pa, int start, int n) throws IOException {
  10. for (int i = 0; i < n; i++) {
  11. writeInt(pa[start + i]);
  12. }
  13. }

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

  1. /**
  2. * Write an array of ints
  3. *
  4. * @param pa write from this array
  5. * @param start starting with this element in the array
  6. * @param n write this number of elements
  7. * @throws IOException on read error
  8. */
  9. public final void writeInt(int[] pa, int start, int n) throws IOException {
  10. for (int i = 0; i < n; i++) {
  11. writeInt(pa[start + i]);
  12. }
  13. }

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

  1. /**
  2. * Write an array of ints
  3. *
  4. * @param pa write from this array
  5. * @param start starting with this element in the array
  6. * @param n write this number of elements
  7. * @throws IOException on read error
  8. */
  9. public final void writeInt(int[] pa, int start, int n) throws IOException {
  10. for (int i = 0; i < n; i++) {
  11. writeInt(pa[start + i]);
  12. }
  13. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. private int writeAttributeValue(Number numValue) throws IOException {
  2. if (numValue instanceof Byte) {
  3. raf.write(numValue.byteValue());
  4. return 1;
  5. } else if (numValue instanceof Short) {
  6. raf.writeShort(numValue.shortValue());
  7. return 2;
  8. } else if (numValue instanceof Integer) {
  9. raf.writeInt(numValue.intValue());
  10. return 4;
  11. } else if (numValue instanceof Float) {
  12. raf.writeFloat(numValue.floatValue());
  13. return 4;
  14. } else if (numValue instanceof Double) {
  15. raf.writeDouble(numValue.doubleValue());
  16. return 8;
  17. }
  18. throw new IllegalStateException("unknown attribute type == " + numValue.getClass().getName());
  19. }

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

  1. private int writeAttributeValue(Number numValue) throws IOException {
  2. if (numValue instanceof Byte) {
  3. raf.write(numValue.byteValue());
  4. return 1;
  5. } else if (numValue instanceof Short) {
  6. raf.writeShort(numValue.shortValue());
  7. return 2;
  8. } else if (numValue instanceof Integer) {
  9. raf.writeInt(numValue.intValue());
  10. return 4;
  11. } else if (numValue instanceof Float) {
  12. raf.writeFloat(numValue.floatValue());
  13. return 4;
  14. } else if (numValue instanceof Double) {
  15. raf.writeDouble(numValue.doubleValue());
  16. return 8;
  17. }
  18. throw new IllegalStateException("unknown attribute type == " + numValue.getClass().getName());
  19. }

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

  1. private int writeAttributeValue(Number numValue) throws IOException {
  2. if (numValue instanceof Byte) {
  3. raf.write(numValue.byteValue());
  4. return 1;
  5. } else if (numValue instanceof Short) {
  6. raf.writeShort(numValue.shortValue());
  7. return 2;
  8. } else if (numValue instanceof Integer) {
  9. raf.writeInt(numValue.intValue());
  10. return 4;
  11. } else if (numValue instanceof Float) {
  12. raf.writeFloat(numValue.floatValue());
  13. return 4;
  14. } else if (numValue instanceof Double) {
  15. raf.writeDouble(numValue.doubleValue());
  16. return 8;
  17. }
  18. throw new IllegalStateException("unknown attribute type == " + numValue.getClass().getName());
  19. }

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

  1. private void writeAtts(List<Attribute> atts, Formatter fout) throws IOException {
  2. int n = atts.size();
  3. if (n == 0) {
  4. raf.writeInt(0);
  5. raf.writeInt(0);
  6. } else {
  7. raf.writeInt(MAGIC_ATT);
  8. raf.writeInt(n);
  9. }
  10. for (int i = 0; i < n; i++) {
  11. if (fout != null) fout.format("***att %d pos= %d%n", i, raf.getFilePointer());
  12. Attribute att = atts.get(i);
  13. writeString(att.getShortName());
  14. int type = getType(att.getDataType());
  15. raf.writeInt(type);
  16. if (type == 2) {
  17. writeStringValues(att);
  18. } else {
  19. int nelems = att.getLength();
  20. raf.writeInt(nelems);
  21. int nbytes = 0;
  22. for (int j = 0; j < nelems; j++)
  23. nbytes += writeAttributeValue(att.getNumericValue(j));
  24. pad(nbytes, (byte) 0);
  25. if (fout != null) fout.format(" end write val pos= %d%n", raf.getFilePointer());
  26. }
  27. if (fout != null) fout.format(" %s%n", att);
  28. }
  29. }

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

  1. private void writeAtts(List<Attribute> atts, Formatter fout) throws IOException {
  2. int n = atts.size();
  3. if (n == 0) {
  4. raf.writeInt(0);
  5. raf.writeInt(0);
  6. } else {
  7. raf.writeInt(MAGIC_ATT);
  8. raf.writeInt(n);
  9. }
  10. for (int i = 0; i < n; i++) {
  11. if (fout != null) fout.format("***att %d pos= %d%n", i, raf.getFilePointer());
  12. Attribute att = atts.get(i);
  13. writeString(att.getShortName());
  14. int type = getType(att.getDataType());
  15. raf.writeInt(type);
  16. if (type == 2) {
  17. writeStringValues(att);
  18. } else {
  19. int nelems = att.getLength();
  20. raf.writeInt(nelems);
  21. int nbytes = 0;
  22. for (int j = 0; j < nelems; j++)
  23. nbytes += writeAttributeValue(att.getNumericValue(j));
  24. pad(nbytes, (byte) 0);
  25. if (fout != null) fout.format(" end write val pos= %d%n", raf.getFilePointer());
  26. }
  27. if (fout != null) fout.format(" %s%n", att);
  28. }
  29. }

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

  1. private void writeAtts(List<Attribute> atts, Formatter fout) throws IOException {
  2. int n = atts.size();
  3. if (n == 0) {
  4. raf.writeInt(0);
  5. raf.writeInt(0);
  6. } else {
  7. raf.writeInt(MAGIC_ATT);
  8. raf.writeInt(n);
  9. }
  10. for (int i = 0; i < n; i++) {
  11. if (fout != null) fout.format("***att %d pos= %d\n", i, raf.getFilePointer());
  12. Attribute att = atts.get(i);
  13. writeString(att.getShortName());
  14. int type = getType(att.getDataType());
  15. raf.writeInt(type);
  16. if (type == 2) {
  17. writeStringValues(att);
  18. } else {
  19. int nelems = att.getLength();
  20. raf.writeInt(nelems);
  21. int nbytes = 0;
  22. for (int j = 0; j < nelems; j++)
  23. nbytes += writeAttributeValue(att.getNumericValue(j));
  24. pad(nbytes, (byte) 0);
  25. if (fout != null) fout.format(" end write val pos= %d\n", raf.getFilePointer());
  26. }
  27. if (fout != null) fout.format(" %s\n", att);
  28. }
  29. }

相关文章