You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RKRecord.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.record;
  16. import java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.poi.hssf.util.RKUtil;
  19. import org.apache.poi.util.GenericRecordUtil;
  20. import org.apache.poi.util.LittleEndianOutput;
  21. /**
  22. * An internal 32 bit number with the two most significant bits storing the type.
  23. * This is part of a bizarre scheme to save disk space and memory (gee look at all the other whole
  24. * records that are in the file just "cause".., far better to waste processor cycles on this then
  25. * leave on of those "valuable" records out).
  26. * We support this in READ-ONLY mode. HSSF converts these to NUMBER records<p>
  27. *
  28. * @see org.apache.poi.hssf.record.NumberRecord
  29. */
  30. public final class RKRecord extends CellRecord {
  31. public static final short sid = 0x027E;
  32. public static final short RK_IEEE_NUMBER = 0;
  33. public static final short RK_IEEE_NUMBER_TIMES_100 = 1;
  34. public static final short RK_INTEGER = 2;
  35. public static final short RK_INTEGER_TIMES_100 = 3;
  36. private int field_4_rk_number;
  37. public RKRecord(RKRecord other) {
  38. super(other);
  39. field_4_rk_number = other.field_4_rk_number;
  40. }
  41. public RKRecord(RecordInputStream in) {
  42. super(in);
  43. field_4_rk_number = in.readInt();
  44. }
  45. /**
  46. * Extract the value of the number
  47. * <P>
  48. * The mechanism for determining the value is dependent on the two
  49. * low order bits of the raw number. If bit 1 is set, the number
  50. * is an integer and can be cast directly as a double, otherwise,
  51. * it's apparently the exponent and mantissa of a double (and the
  52. * remaining low-order bits of the double's mantissa are 0's).
  53. * <P>
  54. * If bit 0 is set, the result of the conversion to a double is
  55. * divided by 100; otherwise, the value is left alone.
  56. * <P>
  57. * [insert picture of Screwy Squirrel in full Napoleonic regalia]
  58. *
  59. * @return the value as a proper double (hey, it <B>could</B>
  60. * happen)
  61. */
  62. public double getRKNumber() {
  63. return RKUtil.decodeNumber(field_4_rk_number);
  64. }
  65. @Override
  66. protected String getRecordName() {
  67. return "RK";
  68. }
  69. @Override
  70. protected void serializeValue(LittleEndianOutput out) {
  71. out.writeInt(field_4_rk_number);
  72. }
  73. @Override
  74. protected int getValueDataSize() {
  75. return 4;
  76. }
  77. @Override
  78. public short getSid() {
  79. return sid;
  80. }
  81. @Override
  82. public RKRecord copy() {
  83. return new RKRecord(this);
  84. }
  85. @Override
  86. public HSSFRecordTypes getGenericRecordType() {
  87. return HSSFRecordTypes.RK;
  88. }
  89. @Override
  90. public Map<String, Supplier<?>> getGenericProperties() {
  91. return GenericRecordUtil.getGenericProperties(
  92. "base", super::getGenericProperties,
  93. "rkNumber", this::getRKNumber
  94. );
  95. }
  96. }