OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimS3StreamBuffer.h
Go to the documentation of this file.
1 //---
2 //
3 // License: MIT
4 //
5 // Author: Garrett Potts
6 //
7 // Description:
8 //
9 // OSSIM Amazon Web Services (AWS) S3 streambuf declaration.
10 //
11 //---
12 // $Id$
13 
14 #ifndef ossimS3StreamBuffer_HEADER
15 #define ossimS3StreamBuffer_HEADER 1
16 
18 #include <aws/s3/S3Client.h>
19 
20 #include "S3StreamDefaults.h"
21 #include <iostream>
22 #include <vector>
23 
24 // namespace Aws
25 // {
26 // namespace S3
27 // {
28 // class S3Client;
29 // }
30 // }
31 
32 class ossimKeywordlist;
33 
34 namespace ossim{
35 class S3StreamBuffer : public std::streambuf
36 {
37 public:
38  class blockInfo
39  {
40  public:
42  :m_startByte(0),
43  m_currentByte(0),
44  m_endByte(0)
45  {
46 
47  }
48 
49  void setBytes(ossim_int64 startByte, ossim_int64 currentByte, ossim_int64 endByte)
50  {
51  m_startByte = startByte;
52  m_currentByte = currentByte;
53  m_endByte = endByte;
54  }
55  void setCurrentByte(ossim_int64 currentByte){m_currentByte = currentByte;}
58  const ossim_int64& getStartByte()const{return m_startByte;}
59  const ossim_int64& getEndByte()const{return m_endByte;}
60  const ossim_int64& getCurrentByte()const{return m_currentByte;}
62 
63 
67  };
68  // S3StreamBuffer(ossim_int64 blockSize=4096);
70 
71  S3StreamBuffer* open (const char* connectionString,
72  const ossimKeywordlist& options,
73  std::ios_base::openmode mode);
74  S3StreamBuffer* open (const std::string& connectionString,
75  const ossimKeywordlist& options,
76  std::ios_base::openmode mode);
77 
78  bool is_open() const
79  {
80  return m_opened;
81  }
82 
83  virtual ~S3StreamBuffer();
84 
88  ossim_uint64 getFileSize() const;
89 
93  ossim_uint64 getBlockSize() const;
94 
95 protected:
96  //virtual int_type pbackfail(int_type __c = traits_type::eof());
97  virtual pos_type seekoff(off_type offset, std::ios_base::seekdir dir,
98  std::ios_base::openmode __mode = std::ios_base::in | std::ios_base::out);
99  virtual pos_type seekpos(pos_type pos,
100  std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
101  virtual std::streamsize xsgetn(char_type* s, std::streamsize n);
102  virtual int underflow();
103 
104  void clearAll();
105 
106  ossim_int64 getBlockIndex(ossim_int64 byteOffset)const;
107  ossim_int64 getBlockOffset(ossim_int64 byteOffset)const;
108  bool getBlockRangeInBytes(ossim_int64 blockIndex,
109  ossim_int64& startRange,
110  ossim_int64& endRange)const;
111 
112  bool loadBlock(ossim_int64 absolutePosition);
113 
114  //void adjustForSeekgPosition(ossim_int64 seekPosition);
116  bool withinWindow()const;
117 
118  //Aws::S3::S3Client* m_client;
119  mutable std::shared_ptr<Aws::S3::S3Client> m_client;
120  std::string m_bucket;
121  std::string m_key;
122  std::vector<char> m_buffer;
125  char* m_bufferPtr;
127  bool m_opened;
129  //std::ios_base::openmode m_mode;
130 };
131 
132 }
133 
134 #endif
std::vector< char > m_buffer
void setBytes(ossim_int64 startByte, ossim_int64 currentByte, ossim_int64 endByte)
bool getBlockRangeInBytes(ossim_int64 blockIndex, ossim_int64 &startRange, ossim_int64 &endRange) const
ossim_int64 getBlockIndex(ossim_int64 byteOffset) const
virtual std::streamsize xsgetn(char_type *s, std::streamsize n)
virtual pos_type seekpos(pos_type pos, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
Represents serializable keyword/value map.
virtual pos_type seekoff(off_type offset, std::ios_base::seekdir dir, std::ios_base::openmode __mode=std::ios_base::in|std::ios_base::out)
const ossim_int64 & getStartByte() const
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
ossim_uint64 getBlockSize() const
const ossim_int64 & getEndByte() const
void setCurrentByte(ossim_int64 currentByte)
os2<< "> n<< " > nendobj n
unsigned long long ossim_uint64
const ossim_int64 & getCurrentByte() const
S3StreamBuffer * open(const char *connectionString, const ossimKeywordlist &options, std::ios_base::openmode mode)
std::shared_ptr< Aws::S3::S3Client > m_client
S3StreamBuffer(ossim_int64 blockSize=ossim::S3StreamDefaults::m_readBlocksize)
ossim_int64 getAbsoluteByteOffset() const
ossim_int64 getBlockOffset(ossim_int64 byteOffset) const
static ossim_int64 m_readBlocksize
long long ossim_int64
bool loadBlock(ossim_int64 absolutePosition)
ossim_uint64 getFileSize() const