Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

PasswordRecord.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.util.GenericRecordUtil;
  19. import org.apache.poi.util.LittleEndianOutput;
  20. /**
  21. * Stores the encrypted password for a sheet or workbook (HSSF doesn't support encryption)
  22. */
  23. public final class PasswordRecord extends StandardRecord {
  24. public static final short sid = 0x0013;
  25. // not sure why this is only 2 bytes, but it is... go figure
  26. private int field_1_password;
  27. public PasswordRecord(int password) {
  28. field_1_password = password;
  29. }
  30. public PasswordRecord(PasswordRecord other) {
  31. super(other);
  32. field_1_password = other.field_1_password;
  33. }
  34. public PasswordRecord(RecordInputStream in) {
  35. field_1_password = in.readShort();
  36. }
  37. /**
  38. * set the password
  39. *
  40. * @param password representing the password
  41. */
  42. public void setPassword(int password) {
  43. field_1_password = password;
  44. }
  45. /**
  46. * get the password
  47. *
  48. * @return short representing the password
  49. */
  50. public int getPassword() {
  51. return field_1_password;
  52. }
  53. public void serialize(LittleEndianOutput out) {
  54. out.writeShort(field_1_password);
  55. }
  56. protected int getDataSize() {
  57. return 2;
  58. }
  59. public short getSid() {
  60. return sid;
  61. }
  62. /**
  63. * Clone this record.
  64. */
  65. public PasswordRecord copy() {
  66. return new PasswordRecord(this);
  67. }
  68. @Override
  69. public HSSFRecordTypes getGenericRecordType() {
  70. return HSSFRecordTypes.PASSWORD;
  71. }
  72. @Override
  73. public Map<String, Supplier<?>> getGenericProperties() {
  74. return GenericRecordUtil.getGenericProperties("password", this::getPassword);
  75. }
  76. }