/*
 * 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.commons.vfs2.provider;

import java.io.InputStream;
import java.util.ArrayList;

import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.RandomAccessContent;

/**
 * Holds the data which needs to be local to the current thread
 */
class FileContentThreadData
{
    // private int state = DefaultFileContent.STATE_CLOSED;

    private final ArrayList<InputStream> instrs = new ArrayList<>();
    private final ArrayList<RandomAccessContent> rastrs = new ArrayList<>();
    private DefaultFileContent.FileContentOutputStream outstr;

    FileContentThreadData()
    {
    }

    /*
    int getState()
    {
        return state;
    }

    void setState(int state)
    {
        this.state = state;
    }
    */

    void addInstr(final InputStream is)
    {
        this.instrs.add(is);
    }

    void setOutstr(final DefaultFileContent.FileContentOutputStream os)
    {
        this.outstr = os;
    }

    DefaultFileContent.FileContentOutputStream getOutstr()
    {
        return this.outstr;
    }

    void addRastr(final RandomAccessContent ras)
    {
        this.rastrs.add(ras);
    }

    int getInstrsSize()
    {
        return this.instrs.size();
    }

    public Object removeInstr(final int pos)
    {
        return this.instrs.remove(pos);
    }

    public void removeInstr(final InputStream instr)
    {
        this.instrs.remove(instr);
    }

    public Object removeRastr(final int pos)
    {
        return this.rastrs.remove(pos);
    }

    public void removeRastr(final RandomAccessContent ras)
    {
        this.rastrs.remove(ras);
    }

    public boolean hasStreams()
    {
        return instrs.size() > 0 || outstr != null || rastrs.size() > 0;
    }

    public void closeOutstr() throws FileSystemException
    {
        outstr.close();
        outstr = null;
    }

    int getRastrsSize()
    {
        return rastrs.size();
    }
}

@@ -1207,20 +1207,29 @@
 ream%3E in
+putStreamLi
 st
-rs
  = new A
@@ -1293,20 +1293,37 @@
 tent%3E ra
+ndomAccessContentLi
 st
-rs
  = new A
@@ -1394,19 +1394,25 @@
 ream out
-str
+putStream
 ;%0A%0A    F
@@ -1622,17 +1622,26 @@
 Stream i
-s
+nputStream
 )%0A    %7B%0A
@@ -1659,19 +1659,37 @@
 s.in
-strs.add(is
+putStreamList.add(inputStream
 );%0A 
@@ -1763,17 +1763,27 @@
 Stream o
-s
+utputStream
 )%0A    %7B%0A
@@ -1802,16 +1802,32 @@
 .out
-str = os
+putStream = outputStream
 ;%0A  
@@ -1919,19 +1919,25 @@
 this.out
-str
+putStream
 ;%0A    %7D%0A
@@ -1975,33 +1975,49 @@
 AccessContent ra
-s
+ndomAccessContent
 )%0A    %7B%0A        
@@ -2027,20 +2027,53 @@
 s.ra
-strs.add(ras
+ndomAccessContentList.add(randomAccessContent
 );%0A 
@@ -2130,20 +2130,29 @@
  this.in
+putStreamLi
 st
-rs
 .size();
@@ -2224,36 +2224,45 @@
   return this.in
+putStreamLi
 st
-rs
 .remove(pos);%0A  
@@ -2314,19 +2314,25 @@
 tream in
-str
+putStream
 )%0A    %7B%0A
@@ -2346,20 +2346,29 @@
  this.in
+putStreamLi
 st
-rs
 .remove(
@@ -2369,19 +2369,25 @@
 emove(in
-str
+putStream
 );%0A    %7D
@@ -2453,36 +2453,53 @@
   return this.ra
+ndomAccessContentLi
 st
-rs
 .remove(pos);%0A  
@@ -2559,17 +2559,33 @@
 ntent ra
-s
+ndomAccessContent
 )%0A    %7B%0A
@@ -2603,23 +2603,56 @@
 s.ra
-strs.remove(ras
+ndomAccessContentList.remove(randomAccessContent
 );%0A 
@@ -2712,20 +2712,29 @@
 eturn in
+putStreamLi
 st
-rs
 .size() 
@@ -2743,19 +2743,25 @@
 0 %7C%7C out
-str
+putStream
  != null
@@ -2766,20 +2766,37 @@
 ll %7C%7C ra
+ndomAccessContentLi
 st
-rs
 .size() 
@@ -2881,19 +2881,25 @@
      out
-str
+putStream
 .close()
@@ -2911,19 +2911,25 @@
      out
-str
+putStream
  = null;
@@ -2983,20 +2983,37 @@
 eturn ra
+ndomAccessContentLi
 st
-rs
 .size();

Less cryptic internal names.