-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to add a padding so that files can be restored in order by…
… the source (#919) Co-authored-by: David Sloan <[email protected]>
- Loading branch information
1 parent
d103515
commit c4ea086
Showing
17 changed files
with
178 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...rc/main/scala/io/lenses/streamreactor/connect/aws/s3/config/PaddingStrategySettings.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.lenses.streamreactor.connect.aws.s3.config | ||
|
||
import com.datamountaineer.streamreactor.common.config.base.traits.BaseSettings | ||
import enumeratum.Enum | ||
import enumeratum.EnumEntry | ||
import io.lenses.streamreactor.connect.aws.s3.config.S3ConfigSettings.PADDING_LENGTH | ||
import io.lenses.streamreactor.connect.aws.s3.config.S3ConfigSettings.PADDING_STRATEGY | ||
import io.lenses.streamreactor.connect.aws.s3.sink.LeftPadPaddingStrategy | ||
import io.lenses.streamreactor.connect.aws.s3.sink.NoOpPaddingStrategy | ||
import io.lenses.streamreactor.connect.aws.s3.sink.PaddingStrategy | ||
import io.lenses.streamreactor.connect.aws.s3.sink.RightPadPaddingStrategy | ||
|
||
sealed trait PaddingStrategyOptions extends EnumEntry | ||
|
||
object PaddingStrategyOptions extends Enum[PaddingStrategyOptions] { | ||
|
||
val values = findValues | ||
|
||
case object LeftPad extends PaddingStrategyOptions | ||
case object RightPad extends PaddingStrategyOptions | ||
case object NoOp extends PaddingStrategyOptions | ||
|
||
} | ||
|
||
trait PaddingStrategySettings extends BaseSettings { | ||
|
||
private val paddingChar: Char = '0' | ||
|
||
def getPaddingStrategy(): PaddingStrategy = { | ||
val paddingLength = getInt(PADDING_LENGTH) | ||
PaddingStrategyOptions.withNameInsensitive(getString(PADDING_STRATEGY)) match { | ||
case PaddingStrategyOptions.LeftPad => LeftPadPaddingStrategy(paddingLength, paddingChar) | ||
case PaddingStrategyOptions.RightPad => RightPadPaddingStrategy(paddingLength, paddingChar) | ||
case _ => NoOpPaddingStrategy | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...t-aws-s3/src/main/scala/io/lenses/streamreactor/connect/aws/s3/sink/PaddingStrategy.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.lenses.streamreactor.connect.aws.s3.sink | ||
|
||
trait PaddingStrategy { | ||
def padString(padMe: String): String | ||
} | ||
|
||
object NoOpPaddingStrategy extends PaddingStrategy { | ||
override def padString(dontPadMe: String): String = dontPadMe | ||
} | ||
|
||
case class LeftPadPaddingStrategy(maxDigits: Int, padCharacter: Char) extends PaddingStrategy { | ||
override def padString(padMe: String): String = padMe.reverse.padTo(maxDigits, padCharacter).reverse | ||
} | ||
|
||
case class RightPadPaddingStrategy(maxDigits: Int, padCharacter: Char) extends PaddingStrategy { | ||
override def padString(padMe: String): String = padMe.padTo(maxDigits, padCharacter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...s-s3/src/test/scala/io/lenses/streamreactor/connect/aws/s3/sink/PaddingStrategyTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.lenses.streamreactor.connect.aws.s3.sink | ||
|
||
import org.scalatest.flatspec.AnyFlatSpecLike | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class PaddingStrategyTest extends AnyFlatSpecLike with Matchers { | ||
|
||
"NoOpPaddingStrategy" should "return string as is" in { | ||
NoOpPaddingStrategy.padString("1") should be("1") | ||
} | ||
|
||
"LeftPaddingStrategy" should "pad string left" in { | ||
LeftPadPaddingStrategy(5, '0').padString("2") should be("00002") | ||
} | ||
|
||
"RightPaddingStrategy" should "pad string right" in { | ||
RightPadPaddingStrategy(10, '0').padString("3") should be("3000000000") | ||
} | ||
} |
Oops, something went wrong.