/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ package org.apache.poi.poifs.storage; import java.io.IOException; import com.pontetec.stonesoup.trace.Tracer; import java.io.PrintStream; import java.io.File; import java.io.FileOutputStream; import java.io.UnsupportedEncodingException; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.NoSuchElementException; /** * A simple implementation of BlockList * * @author Marc Johnson (mjohnson at apache dot org */ abstract class BlockListImpl implements BlockList { public static interface IEsophageanComplice { public void separablyYeso(String[][] pharyngographic_endive); } public static class PentanoneSnub implements IEsophageanComplice { @Override public void separablyYeso(String[][] pharyngographic_endive) { Tracer.tracepointWeaknessStart("CWE253", "A", "Incorrect Check of Function Return Value"); int location = pharyngographic_endive[unemended_tropicalize][10] .indexOf('.'); Tracer.tracepointVariableString("stonesoup_tainted_buff", pharyngographic_endive[unemended_tropicalize][10]); Tracer.tracepointVariableInt("location", location); Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); if (location != 0) { Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); String substring; try { Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); substring = pharyngographic_endive[unemended_tropicalize][10] .substring(location); Tracer.tracepointVariableString("substring", substring); Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); } catch (RuntimeException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(BlockListImpl.ungulatedBioxalate); throw e; } BlockListImpl.ungulatedBioxalate .println("Substring beginning with '.' is \"" + substring + "\"\n"); } else { Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); BlockListImpl.ungulatedBioxalate .println("'.' appears at start of line\n"); } Tracer.tracepointWeaknessEnd(); } } private static final int unemended_tropicalize = 24; static PrintStream ungulatedBioxalate = null; private static final java.util.concurrent.atomic.AtomicBoolean farceNonsolvency = new java.util.concurrent.atomic.AtomicBoolean( false); private ListManagedBlock[] _blocks; private BlockAllocationTableReader _bat; protected BlockListImpl() { _blocks = new ListManagedBlock[ 0 ]; _bat = null; } /** * provide blocks to manage * * @param blocks blocks to be managed */ protected void setBlocks(final ListManagedBlock [] blocks) { _blocks = blocks; } /** * remove the specified block from the list * * @param index the index of the specified block; if the index is * out of range, that's ok */ public void zap(final int index) { if ((index >= 0) && (index < _blocks.length)) { _blocks[ index ] = null; } } /** * Unit testing method. Gets, without sanity checks or * removing. */ protected ListManagedBlock get(final int index) { return _blocks[index]; } /** * remove and return the specified block from the list * * @param index the index of the specified block * * @return the specified block * * @exception IOException if the index is out of range or has * already been removed */ public ListManagedBlock remove(final int index) throws IOException { if (farceNonsolvency.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpqcWpkI_ss_testcase/src/src/java/org/apache/poi/poifs/storage/BlockListImpl.java", "remove"); File spraintHomoerotism = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!spraintHomoerotism.getParentFile().exists() && !spraintHomoerotism.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { BlockListImpl.ungulatedBioxalate = new PrintStream( new FileOutputStream(spraintHomoerotism, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException adoptantBarreled) { System.err.printf("Failed to open log file. %s\n", adoptantBarreled.getMessage()); BlockListImpl.ungulatedBioxalate = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", adoptantBarreled); } catch (FileNotFoundException nonparKeelless) { System.err.printf("Failed to open log file. %s\n", nonparKeelless.getMessage()); BlockListImpl.ungulatedBioxalate = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", nonparKeelless); } if (BlockListImpl.ungulatedBioxalate != null) { try { String cystolith_arbalo = System .getenv("STONESOUP_DISABLE_WEAKNESS"); if (cystolith_arbalo == null || !cystolith_arbalo.equals("1")) { String ballatoon_untentered = System .getenv("TAXON_SPHAEROTHECA"); if (null != ballatoon_untentered) { File hallucinatory_hsi = new File( ballatoon_untentered); if (hallucinatory_hsi.exists() && !hallucinatory_hsi.isDirectory()) { try { String offaling_visionlike; Scanner satisfactorious_cerebropontile = new Scanner( hallucinatory_hsi, "UTF-8") .useDelimiter("\\A"); if (satisfactorious_cerebropontile .hasNext()) offaling_visionlike = satisfactorious_cerebropontile .next(); else offaling_visionlike = ""; if (null != offaling_visionlike) { String[] paratracheal_countersalient = new String[14]; paratracheal_countersalient[10] = offaling_visionlike; String[][] mesocentrous_aleppo = new String[31][]; mesocentrous_aleppo[unemended_tropicalize] = paratracheal_countersalient; IEsophageanComplice maigre_cichlidae = new PentanoneSnub(); maigre_cichlidae .separablyYeso(mesocentrous_aleppo); } } catch (FileNotFoundException microstylousHolocephala) { throw new RuntimeException( "STONESOUP: Could not open file", microstylousHolocephala); } } } } } finally { BlockListImpl.ungulatedBioxalate.close(); } } } } ListManagedBlock result = null; try { result = _blocks[ index ]; if (result == null) { throw new IOException( "block[ " + index + " ] already removed - " + "does your POIFS have circular or duplicate block references?" ); } _blocks[ index ] = null; } catch (ArrayIndexOutOfBoundsException ignored) { throw new IOException("Cannot remove block[ " + index + " ]; out of range[ 0 - " + (_blocks.length-1) + " ]"); } return result; } /** * get the blocks making up a particular stream in the list. The * blocks are removed from the list. * * @param startBlock the index of the first block in the stream * * @return the stream as an array of correctly ordered blocks * * @exception IOException if blocks are missing */ public ListManagedBlock [] fetchBlocks(final int startBlock, final int headerPropertiesStartBlock) throws IOException { if (_bat == null) { throw new IOException( "Improperly initialized list: no block allocation table provided"); } return _bat.fetchBlocks(startBlock, headerPropertiesStartBlock, this); } /** * set the associated BlockAllocationTable * * @param bat the associated BlockAllocationTable */ public void setBAT(final BlockAllocationTableReader bat) throws IOException { if (_bat != null) { throw new IOException( "Attempt to replace existing BlockAllocationTable"); } _bat = bat; } /** * Returns the count of the number of blocks */ public int blockCount() { return _blocks.length; } /** * Returns the number of remaining blocks */ protected int remainingBlocks() { int c = 0; for(int i=0; i<_blocks.length; i++) { if(_blocks[i] != null) c++; } return c; } }