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.

SSTDeserializer.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 org.apache.logging.log4j.LogManager;
  17. import org.apache.logging.log4j.Logger;
  18. import org.apache.poi.hssf.record.common.UnicodeString;
  19. import org.apache.poi.util.IntMapper;
  20. import static org.apache.logging.log4j.util.Unbox.box;
  21. /**
  22. * Handles the task of deserializing a SST string. The two main entry points are
  23. *
  24. * @author Glen Stampoultzis (glens at apache.org)
  25. * @author Jason Height (jheight at apache.org)
  26. */
  27. class SSTDeserializer
  28. {
  29. private static final Logger LOG = LogManager.getLogger(SSTDeserializer.class);
  30. private IntMapper<UnicodeString> strings;
  31. public SSTDeserializer( IntMapper<UnicodeString> strings )
  32. {
  33. this.strings = strings;
  34. }
  35. /**
  36. * This is the starting point where strings are constructed. Note that
  37. * strings may span across multiple continuations. Read the SST record
  38. * carefully before beginning to hack.
  39. */
  40. public void manufactureStrings( int stringCount, RecordInputStream in )
  41. {
  42. for (int i=0;i<stringCount;i++) {
  43. // Extract exactly the count of strings from the SST record.
  44. UnicodeString str;
  45. if (in.available() == 0 && !in.hasNextRecord()) {
  46. LOG.atError().log("Ran out of data before creating all the strings! String at index {}", box(i));
  47. str = new UnicodeString("");
  48. } else {
  49. str = new UnicodeString(in);
  50. }
  51. addToStringTable( strings, str );
  52. }
  53. }
  54. static public void addToStringTable( IntMapper<UnicodeString> strings, UnicodeString string )
  55. {
  56. strings.add(string);
  57. }
  58. }